Click to See Complete Forum and Search --> : shuffle(List<?> list, Random rnd)?
Dillinger4
Jul 17th, 2005, 09:32 PM
Ive been wondering what the random number generator thats used as an arg to the shuffle method applies to. Does it apply to the probability that a List will have it's elements end up in the same sequence after being shuffled multiple times? If so how can the probability be increased or decreased? Thanks. :)
NoteMe
Jul 18th, 2005, 01:55 AM
I think it is just that random object it uses for the shuffeling. So it has nothing to do with probability. So I guess that if you seed the random object with the same number 2 times, and pass it into the shuffle method, then you will get the same order. If you do not seed it with the same number, then you will get different (at least in theory) order of the elements.
- ии -
CornedBee
Jul 18th, 2005, 12:09 PM
A typical shuffling algo looks like this:
for i is 0 to list size do
j = random between 0 and list size
swap list[i] and list[j]
done
The Random object is the source of the random numbers.
NoteMe
Jul 18th, 2005, 12:20 PM
So I guess my seeding theory holds...:)
- ии -
Dillinger4
Jul 18th, 2005, 03:12 PM
Posted by NoteMe
So I guess that if you seed the random object with the same number 2 times, and pass it into the shuffle method, then you will get the same order.
Yes according to java.util.Random docs that is correct.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.