monte carlo random number generation
Show older comments
i want to use a function that generates a random number from [1,2,3,4,5,6,7,8,9,10] but the probabilities of each number are different. For exaample the pof drawing one is 0.2 but p of drawing 3 is 0.06? is there a function or a code that i can use in order to generate a random number by taking into consideration that each number has different weighting?
Accepted Answer
More Answers (1)
Image Analyst
on 29 Mar 2021
You can simply get the cumulative sum and compare your random number to that. For example
r = rand
c = cumsum(p)
output = find(r < c, 1, 'last')
If that doesn't work for you, then give us all the probability values.
1 Comment
stavros boutsikos
on 29 Mar 2021
Categories
Find more on Uniform Distribution (Continuous) in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!