Home arrow static arrow Java Programming [Archive] - more random
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - more random
This topic has 16 replies on 2 pages.    « Previous | 1 | 2 |

Posts:12,831
Registered: 2/22/00
Re: more random  
Aug 2, 2004 9:20 PM (reply 15 of 16)



 
"more random" - pretty funny!

Hmmm...
public class SwitchableRandom {    public boolean truly_random = true;    private Random r = new Random();    public int nextInt() {        return truly_random ? r.nextInt() : 5;    }}//... in use:SwitchableRandom r = new SwitchableRandom();System.out.println("random: " + r.nextInt());r.truly_random = false;System.out.println("not random: " + r.nextInt());

The next step would be to make the randomness configurable to a finer granularity.
 

Posts:5,965
Registered: 5/17/03
Re: more random  
Aug 2, 2004 9:37 PM (reply 16 of 16)



 
"more random" - pretty funny!

Random generators can be more or less random. For example the length of the random sequence cycle and the evenness of the number distribution etcetera. NextInt(int n) of Random uses special tricks to enhance its randomness.
 
This topic has 16 replies on 2 pages.    « Previous | 1 | 2 |