Results 1 to 5 of 5

Thread: shuffle(List<?> list, Random rnd)?

  1. #1

    Thread Starter
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418

    shuffle(List<?> list, Random rnd)?

    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.

  2. #2
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    Re: shuffle(List<?> list, Random rnd)?

    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.


    - ØØ -

  3. #3
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: shuffle(List<?> list, Random rnd)?

    A typical shuffling algo looks like this:
    Code:
    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.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  4. #4
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    Re: shuffle(List<?> list, Random rnd)?

    So I guess my seeding theory holds...


    - ØØ -

  5. #5

    Thread Starter
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418

    Re: shuffle(List<?> list, Random rnd)?

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width