Welcome to SPN

Register and Join the most happening forum of Sikh community & intellectuals from around the world.

Sign Up Now!

Sorry meant Rnd number duplication

Discussion in 'Information Technology' started by RioDeSmoke, Nov 19, 2005.

  1. RioDeSmoke

    RioDeSmoke
    Expand Collapse
    Guest

    I have some code that loops through a Recordset in order to select an X
    amount of random records. When I select 10 records I get 10 -- 20 I get 20
    and so on. But, when I select 400, I get 369 at times and 381 at others.
    The difference gets greater the more records I select. I believe what is
    happening is that the random numbers being generated are being duplicated and
    it can't select the record more than once. Here is my code within my loop:

    MyRS.MoveLast
    NumOfRecords = MyRS.RecordCount
    Randomize
    SpecificRecord = Int((NumOfRecords * Rnd) + 1)

    Has anyone ever seen this? Please help if you can this is driving me crazy!
     
  2. Loading...

    Similar Threads Forum Date
    I Just Wanted To Say Sorry Hard Talk Mar 3, 2016
    Self Swapping "sorry" For "thank You" Blogs Feb 13, 2016
    Malaysia Again and Again! "We are sorry" Says Buddhist Chief High Priest to Muslim Public Breaking News Aug 13, 2013
    To God/Creator: “Thank You”, “I Am Sorry” or Nothing! Sikh Sikhi Sikhism Sep 8, 2012
    Islam Message to Muslims: I'm Sorry Interfaith Dialogues Sep 20, 2010

  3. John Vinson

    John Vinson
    Expand Collapse
    Guest

    On Fri, 18 Nov 2005 18:45:07 -0800, "RioDeSmoke"
    <RioDeSmoke@discussions.microsoft.com> wrote:

    >I have some code that loops through a Recordset in order to select an X
    >amount of random records. When I select 10 records I get 10 -- 20 I get 20
    >and so on. But, when I select 400, I get 369 at times and 381 at others.
    >The difference gets greater the more records I select. I believe what is
    >happening is that the random numbers being generated are being duplicated and
    >it can't select the record more than once. Here is my code within my loop:
    >
    > MyRS.MoveLast
    > NumOfRecords = MyRS.RecordCount
    > Randomize
    > SpecificRecord = Int((NumOfRecords * Rnd) + 1)
    >
    >Has anyone ever seen this? Please help if you can this is driving me crazy!


    Well, if you pick truly random integers in the range 1 to 400, then
    absolutely, you WILL get duplicates. If you put 400 numbered beads in
    a bag, and draw twenty with replacement, there's a very good chance
    that you'll draw the same one twice; if you draw 100, it's almost a
    certainty.

    If you want to select 400 randomly chosen records from a recordset,
    add a calculated random number field; *sort* ascending (or descending,
    makes no difference) by it to shuffle the records into random order;
    and use the Top Values property of the query to select the top 400
    records.

    John W. Vinson[MVP]
     

Share This Page