View Single Post
Old 01-08-2013, 08:05 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
When it comes to random, simply don't seed it. If you provide two random instances which happen to have the same seed, than the random numbers they draw would be the same:
PHP Code:
        Random r1 = new Random(5);
        
Random r2 = new Random(5);
        for (
int i 05; ++i)
        {
            
System.out.println("Random 1 pulled: " r1.nextInt());
            
System.out.println("Random 2 pulled: " r2.nextInt());
            
System.out.println();
        } 
So despite two completely separate instances of Random, both of them will randomly select the same numbers on each call to next. Simply don't seed it and that behaviour will disappear.
You should consider using integers to store these in. You can display them as floating by dividing by 100, but there is rounding violations that occur due to both limitation in hardware as well as base conversion (ie: 1/10 in base2 cannot be represented as an even number and so repeats infinitely). This can cause havoc although likely will not be a problem when dealing with such low fractional values (and more importantly, ones that do not operate on them).
If you're interested in these, you can find a large number of resources if you search for computational mathematics. I'd have to dust the old book off otherwise :P
Fou-Lu is offline   Reply With Quote