+ Reply to Thread
Results 1 to 4 of 4

Strange RAND results

  1. #1
    Registered User
    Join Date
    05-08-2010
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    2

    Question Strange RAND results

    I have just had some strange RAND results, which I have narrowed down to a simple repeatable case. Am I doing something wrong?

    I have filled 20,000 rows with 3 columns. Column A and B contains =ROUND(RAND()*2,0)+1, to generate a random integer between 1 and 3. C1 contains =IF(A1=B1,1,0), C2 contains =IF(A2=B2,1,0), etc. Basically column C is set to 1 if the random numbers in A and B match, otherwise it is set to 0.

    The average of columns A and B are close to 2, as expected. However, the average of column C is always around 37%, instead of the expected 33%.

    Can anyone help with this please?

  2. #2
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Strange RAND results

    why not use =randbetween(1,3) this will give you your expected 33% dont know why the other doesnt as i agree it consistently gives around 37%(ah this is because its more likely to round to 2 than anything else)
    if you try
    =COUNTIF($A$1:$A$2000,1) and =COUNTIF($A$1:$A$2000,2) and =COUNTIF($A$1:$A$2000,3) you will see a disproportinate count of 2
    Last edited by martindwilson; 05-08-2010 at 07:27 AM.
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  3. #3
    Registered User
    Join Date
    05-08-2010
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Strange RAND results

    never heard of randbetween, but does exactly what I want, thanks. Just goes to show that RAND() should be used with care!

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Strange RAND results

    It's not the RAND() that's causing the 'odd' results, it's the ROUND, which reduces probability of the endpoints. You're generating a random number from 0 to 2. After the round,

    0.0 to 0.5 returns 0 (25% probability)
    0.5 to 1.5 returns 1 (50% probability)
    1.5 to 2.0 returns 2 (25% probability)

    RANDBETWEEN is the simple solution, but if you wanted to use RAND,

    =INT(RAND() * 3) + 1
    Entia non sunt multiplicanda sine necessitate

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1