Results 1 to 11 of 11
Thread: Trying to Generate Random number
 01132009, 07:49 AM #1Member
 Join Date
 Jan 2009
 Posts
 22
 Rep Power
 0
Trying to Generate Random number
Java Code:import java.util.Random; public class mainMemory { public static void main(String[] args) { //Int Fragmentation int iFrag2=2, iFrag3=3, iFragT ; [COLOR="Red"][B] int iFrag1 = generator.nextInt(6) + 1;[/B][/COLOR] iFragT=iFrag1+iFrag2+iFrag3; //Ext Fragmentation int eFrag1=100, eFrag2=300, eFrag3=600, eFragT ; eFragT=eFrag1+eFrag2+eFrag3; // System.out.println("Internal Frag: " +iFrag1 +" Kb"); System.out.println("Internal Frag: " +eFragT +" Kb"); } }
In JCreator it returns error at the line in red:
1) cannot find symbol variable generator
2) operator + cannot be applied to generator.nextInt, int
3) imcompatible types
 01132009, 08:16 AM #2
 Join Date
 Jul 2007
 Location
 Colombo, Sri Lanka
 Posts
 11,372
 Blog Entries
 1
 Rep Power
 19
Just try to sort out random number generating. Later added into your application.
 01132009, 08:50 AM #3Senior Member
 Join Date
 Dec 2008
 Location
 Hong Kong
 Posts
 473
 Rep Power
 6
you have not declare and initialize your "generator"
 01132009, 08:54 AM #4
 Join Date
 Jul 2007
 Location
 Colombo, Sri Lanka
 Posts
 11,372
 Blog Entries
 1
 Rep Power
 19
He just copied a line of code from that page I've send in earlier thread, without reading that.
 01132009, 05:05 PM #5Member
 Join Date
 Jan 2009
 Posts
 22
 Rep Power
 0
Java Code:import java.util.Random; public class mainMemory { public static void main(String[] args) { Random generator = new Random(); //MemorySize int mem1 = generator.nextInt(999); int mem2 = generator.nextInt(999); int mem3 = generator.nextInt(999); int mem4 = generator.nextInt(999); int mem5 = generator.nextInt(999); //Memory Allocation int memA1 = generator.nextInt(999); int memA2 = generator.nextInt(999); int memA3 = generator.nextInt(999); int memA4 = generator.nextInt(999); int memA5 = generator.nextInt(999); //Int Fragmentation int iFrag= (mem1memA1)+(mem2memA2)+(mem3memA3)+(mem4memA4)+(mem5memA5); //Ext Fragmentation int eFrag1=100, eFrag2=300, eFrag3=600, eFragT ; eFragT=eFrag1+eFrag2+eFrag3; // System.out.println(" "+mem1 +"Kb  " +mem2 +"Kb  " +mem3 +"Kb  " +mem4 +"Kb  " +mem5 +"kb"); System.out.println(" "+memA1 +"Kb  " +memA2 +"Kb  " +memA3 +"Kb  " +memA4 +"Kb  " +mem5 +"kb \n\n"); System.out.println("Internal Frag: " +iFrag +" Kb"); System.out.println("Internal Frag: " +eFragT +" Kb"); } }
 01132009, 05:27 PM #6
Memory Lane
If it's from Oklahoma, it's okay.
Java Code:import java.security.SecureRandom; public class MemoryLane { public static void main(String[] args) { SecureRandom rabi_dambi = SecureRandom.getInstance("SHA1PRNG"); //MemorySize int mem1 = rabi_dambi.nextInt(999); int mem2 = rabi_dambi.nextInt(999); int mem3 = rabi_dambi.nextInt(999); int mem4 = rabi_dambi.nextInt(999); int mem5 = rabi_dambi.nextInt(999); //Memory Allocation int memA1 = rabi_dambi.nextInt(999); int memA2 = rabi_dambi.nextInt(999); int memA3 = rabi_dambi.nextInt(999); int memA4 = rabi_dambi.nextInt(999); int memA5 = rabi_dambi.nextInt(999); //... remainder as you had it. } }
Introduction to Programming Using Java.
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor
 01142009, 05:10 AM #7Member
 Join Date
 Jan 2009
 Posts
 22
 Rep Power
 0
I found this on suns website, but can someone reduce it to layman terms? What is the diff between secureRandom and random?
This class provides a cryptographically strong pseudorandom number generator (PRNG). A cryptographically strong pseudorandom number minimally complies with the statistical random number generator tests specified in FIPS 1402, Security Requirements for Cryptographic Modules, section 4.9.1. Additionally, SecureRandom must produce nondeterministic output and therefore it is required that the seed material be unpredictable and that output of SecureRandom be cryptographically strong sequences as described in RFC 1750: Randomness Recommendations for Security.
Like other algorithmbased classes in Java Security, SecureRandom provides implementationindependent algorithms, whereby a caller (application code) requests a particular PRNG algorithm and is handed back a SecureRandom object for that algorithm. It is also possible, if desired, to request a particular algorithm from a particular provider. See the getInstance methods.
 01142009, 05:53 AM #8Senior Member
 Join Date
 Nov 2008
 Posts
 286
 Rep Power
 6
Generally, if you need to use SecureRandom, you'll know you need to. Otherwise, don't worry about it.
Although the numbers it produces seem "random to the naked eye", Random actually uses a fairly simple formula (a socalled Linear Congruential Generator). So it would be no good using Random to generate, say, session numbers for a web site. If you did, then Person A could log on to the site, see the session number they were given, and then guess Person B's (or lots of other people's) session number. SecureRandom uses an algorithm that is slower, but which makes it much more difficult for an observer to guess the next or previous numbers in the sequence.Neil Coffey
Javamex  Java tutorials and performance info
 01142009, 06:10 AM #9Member
 Join Date
 Jan 2009
 Posts
 22
 Rep Power
 0
i see. thanks man!
 01142009, 06:13 AM #10
Math.random
What is the diff between secureRandom and random?Java Code:import java.util.Random; //... Random radon = new Random(); radon.nextInt();
mtyoung you have not declare and initialize your "generator"
newbies, oh the fun!Introduction to Programming Using Java.
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor
 01142009, 08:37 AM #11Java Code:
Math.random()
Introduction to Programming Using Java.
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor
Similar Threads

How do I generate random numbers in a certain range using the random class?
By frasifrasi in forum New To JavaReplies: 8Last Post: 04192009, 05:50 PM 
Random number help
By jgonzalez14 in forum New To JavaReplies: 5Last Post: 09162008, 09:13 AM 
Random number
By jithan in forum Advanced JavaReplies: 1Last Post: 06132008, 01:42 PM 
Generate a random number
By romina in forum New To JavaReplies: 1Last Post: 08072007, 05:23 AM 
How to generate random number in java
By fernando in forum New To JavaReplies: 1Last Post: 08012007, 07:32 PM
Bookmarks