A random number generator from a specified distirbution | XM Community
Skip to main content
Solved

A random number generator from a specified distirbution

  • October 25, 2021
  • 4 replies
  • 74 views

Forum|alt.badge.img+2

Dear all,
As the question describes, I'd like to generate a random number but from a specific distribution. For example, there is 80% chance that the random number is 1, 10% chance that the number is 2 and 10% chance it is 3. I tried both the random generator from the piped text and Randomiser. But I failed to specify the distribution that the random number is drawn from. Any idea how to accomplish this?

Thank you very much!

Best answer by ahmedA

You'll have to build it yourself.
The easiest solution is to define your distribution, put it in an array and pull one number randomly from that array.
In the example you've given above, you'll have to create an array with eight 1s, and one each of 2 and 3.
Then pull one number randomly from the array.

4 replies

Forum|alt.badge.img+22
  • Level 7 ●●●●●●●
  • Answer
  • October 25, 2021

You'll have to build it yourself.
The easiest solution is to define your distribution, put it in an array and pull one number randomly from that array.
In the example you've given above, you'll have to create an array with eight 1s, and one each of 2 and 3.
Then pull one number randomly from the array.


BogdanSB
Level 1 ●
Forum|alt.badge.img+4
  • Level 1 ●
  • October 25, 2021

Maybe you can try a formula based on the minutes of the hour the survey is taken. If it's between 0 and 47 (70% of 60 mins) is 1, between 48 and 53 (10% of 60 mins) is 2 and between 54 and 60 is 3.


Forum|alt.badge.img+2
  • Author
  • October 26, 2021

Thank you both for your excellent ideas! I'll give them a try.


BogdanSB
Level 1 ●
Forum|alt.badge.img+4
  • Level 1 ●
  • November 3, 2021

Thank you, xwan8838 for being open to suggestions! 😀