+ Reply to Thread
Results 1 to 5 of 5

Generate random number from probability

  1. #1
    Registered User
    Join Date
    10-14-2013
    Location
    Gothenburg, Sweden
    MS-Off Ver
    Excel 2010
    Posts
    3

    Generate random number from probability

    Hi! I just registered here. Hopefully you guys might be able to help me with a problem

    I would like to generate a random number (0 or 1) where the probability of getting a 1 is determined by another cell with a probability.

    For example if the probability value in the cell is 0.75 then the random number would be 1 75% of the time and 0 25% of the time.

    My plan is to have a long column (1000+ rows) with probablities and then generate the 0 or 1 in the next column for each probability.

    Is this possible to do with formulas or do I have to involve VBA/macros?

    Thank you!

  2. #2
    Forum Expert ben_hensel's Avatar
    Join Date
    01-26-2012
    Location
    Northeast USA
    MS-Off Ver
    Office 365
    Posts
    2,043

    Re: Generate random number from probability

    I would do it like this:

    A1 = percent probability of returning 1
    B1 = IF(RAND() < A1, 1, 0)

    Then pull B down.
    Note you will need to set it to a non-relative reference (that is, $A$1 instead of A1) if you want all the functions to refer to the same cell instead of the one next to it.

    This will use the RAND function to pseudorandomly generate a number anywhere between 0 and 1, and then you compare that to the "probably threshold" to return your boolean.

  3. #3
    Registered User
    Join Date
    10-14-2013
    Location
    Gothenburg, Sweden
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Generate random number from probability

    Quote Originally Posted by ben_hensel View Post
    I would do it like this:

    A1 = percent probability of returning 1
    B1 = IF(RAND() < A1, 1, 0)

    Then pull B down.
    Note you will need to set it to a non-relative reference (that is, $A$1 instead of A1) if you want all the functions to refer to the same cell instead of the one next to it.

    This will use the RAND function to pseudorandomly generate a number anywhere between 0 and 1, and then you compare that to the "probably threshold" to return your boolean.
    Thank you!
    I feel kinda stupid now considering how easy it was

  4. #4
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Generate random number from probability

    Based on your last post in this thread, its apparent that you are satisfied with the solution(s) you've received and have solved your question, but you haven't marked your thread as "SOLVED". I will do it for you this time.

    In future, to mark your thread as Solved, you can do the following -
    Select Thread Tools-> Mark thread as Solved.

    Incase your issue is not solved, you can undo it as follows -
    Select Thread Tools-> Mark thread as Unsolved.

    Also, since you are relatively new to the forum, i would like to inform you that you can thank those who have helped you by clicking the small star icon located in the lower left corner of the post which helped you. This adds to the reputation of the person who has taken the time to help you.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  5. #5
    Registered User
    Join Date
    10-14-2013
    Location
    Gothenburg, Sweden
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Generate random number from probability

    Ok done. thx

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 5
    Last Post: 06-21-2013, 10:40 AM
  2. Replies: 1
    Last Post: 03-26-2013, 02:24 PM
  3. Need Random Number Generator but with Weighted Probability for Certain Numbers...
    By michaeljoeyeager in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 07-13-2012, 03:52 PM
  4. Return random number based on probability
    By gazza365 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-28-2011, 08:46 PM
  5. generate a random number and use if function to generate new data
    By Dogdoc1142 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 04-25-2006, 10:50 PM

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