Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

generating random_numbers with different probability

Status
Not open for further replies.

sajnam

Technical User
Jan 31, 2006
2
GB
Hi,

I was wondering is it possible to use random_number generator, and assign different weights to the outcome. So for example, If I wanted it to generate either the number 1 or 2, but how could I tell it that the probability of generating 2 should be say 70%, and the probability of generating 1 is 30%. Then get it to run and see how many times I get the ans 1 and how many times I get 2. Like rolling a dice, only the probability of rolling one number over the others is greater.
Would appreciate anyones help with this.
Thank you.
 
Obvious pseudocode (suppose frand returns 0..1 pseudo random numbers):
Code:
if frand() <= 0.7 then
   return 2
else
   return 1
See any book about applied math statistics...
 
Thank you. Thats brilliant, and so simple.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top