So I know I can call random(long val)
in Java to generate a random number with a seed of 2^63. How would one do better (larger seed value)? I'm assuming this would have to be a manual class to perform such an accomplishment, but I'm a little lost as how to begin.
Asked
Active
Viewed 204 times
1

WildBill
- 9,143
- 15
- 63
- 87
-
5What do you want to make "better"? "Better randomness" can be had with SecureRandom. – Thilo Jul 05 '12 at 02:22
-
Ahh, I was not aware of this library. LEt me look up an example of how to use it. Do you know what its limits are? – WildBill Jul 05 '12 at 02:32
-
So I'm a little confused as how large the default seed is with SecureRandom. If my random number is created using the following code 'Random ranGen = new SecureRandom();', how big is the seed? – WildBill Jul 05 '12 at 04:45
-
1See: [Neil Coffey's](http://stackoverflow.com/users/48933/neil-coffey) answer to ***[How good is java.util.Random?](http://stackoverflow.com/a/453554/1164465)*** and the ***[SecureRandom documentation](http://docs.oracle.com/javase/6/docs/api/java/security/SecureRandom.html)*** – Christopher Peisert Jul 05 '12 at 06:39
1 Answers
0
Two ways to increase the amount of seed material are:
- use an RNG designed to accept a lot of seed material.
- combine two different RNGs.
For the first, look at some of George Marsaglia's methods, which use arrays to hold their state. There is an example at http://programmingpraxis.com/2010/10/05/george-marsaglias-random-number-generators/ (be careful to note the correction in the comments:
#define SHR3 (jsr^=(jsr<>17), jsr^=(jsr<<5))
The array t[256] is where most of the seed is held.
For the second, look at Pierre L'Ecuyer's work, for example, Efficient and Portable Combined Random Number Generators

rossum
- 15,344
- 1
- 24
- 38