1

I would like to generate 50 integers randomly taken from 7, 15 and 35. I understand we can specify the range using

int random = (int )(Math. random() * 50 + 1) 

will generate an integer from 1-50 but how can generate only 7, 15 or 35?

user3841581
  • 2,637
  • 11
  • 47
  • 72
  • 1
    Actually, this is not a good way of generating a range. It is biased. – weston Dec 29 '16 at 13:19
  • Trying to find something to back that claim up, in meantime, this is how you can get a range in a better way: http://stackoverflow.com/questions/363681/generating-random-integers-in-a-specific-range – weston Dec 29 '16 at 13:26
  • Found evidence of why this approach is biased: http://stackoverflow.com/questions/738629/math-random-versus-random-nextintint – weston Dec 29 '16 at 13:34

0 Answers0