Welcome to SPN

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

Sign Up Now!
  1. Monthly (Recurring) Target: $300 :: Achieved: $95
      Become a Supporter    ::   Make a Contribution   

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]
     
Since you're here... we have a small favor to ask...

More people are visiting & reading SPN than ever but far fewer are paying to sustain it. Advertising revenues across the online media have fallen fast. So you can see why we need to ask for your help. Donating to SPN's is vote for free speech, for diversity of opinions, for the right of the people to stand up to religious bigotry. Without any affiliation to any organization, this constant struggle takes a lot of hard work to sustain as we entirely depend on the contributions of our esteemed writers/readers. We do it because we believe our perspective matters – because it might well be your perspective, too... Fund our efforts and together we can keep the world informed about the real Sikh Sikhi Sikhism. If everyone who writes or reads our content, who likes it, helps us to pay for it, our future would be much more secure. Every Contribution Matters, Contribute Generously!

    Become a Supporter      ::     Make a Contribution     



Share This Page