Random number generator with a range: how to exclude values based on participant response? | XM Community
Question

Random number generator with a range: how to exclude values based on participant response?

  • 8 July 2020
  • 1 reply
  • 26 views

Hello, I am attempting to construct a question and answer series wherein the participant states a percentage between 0 and 100, and then a random number generator gives a percentage. We're hoping to make certain that the RNG does not repeat the same percentage as the participant response. Is there code to exclude the participant response percentage from the range that the RNG could output?
Thanks.


1 reply

Userlevel 7
Badge +27

Using JS, you can make sure that the random number is different from the input number by using a while loop:
var rng;
while((rng=Math.round(Math.random() * 100)) == inNum);

Leave a Reply