Results 1 to 4 of 4

Thread: Rnd Function Help

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2000
    Location
    Chesterfield, UK
    Posts
    298

    Rnd Function Help

    I am trying to use the rnd function to get a random number(ironically enough).

    What I would like it to do would be to return smaller numbers more frequently than larger numbers.

    For example, the number 1 will be returned a lot more frequently than the number 5.

    Would you have any advice??

    Thanks,


    Matt.

  2. #2
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    Well, you want a distibution of numbers that is weighted on one side instead of evenly.

    Unfortunately, I remember jack from statistics, but in any case, it would probably involve keeping a running tab of how many 'undesireable' numbers fell out of range. And if that running count is too high, discard that random number and try again.

    1) get a random number
    2) add +1 to your generated number count
    3) if its out of your desirable range,
    3aaa) add +1 to your undesirable number count
    3aab) if the undesirable count is not too high,
    use that number,
    3bbb) if it is too high, discard that generated number, grab another one.

    EDIT: keep a running count of generated/undesirable as a ratio. If the ratio becomes too large, try generating another random number.

  3. #3
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Alternatively you can generate the random number between 1 and 10 then subtract 5 and round to the first positive number. Then you would have a 6 to 1 chance of getting the number 1.

  4. #4
    Lively Member
    Join Date
    Nov 2003
    Location
    Iowa
    Posts
    96
    Wouldn't that not be random?
    It is like wiping your ass with silk, I love it!

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