WeBWorK Problems

Generate distinct random values

Re: Generate distinct random values

by Nathan Wodarz -
Number of replies: 0
My solution when I had the same problem that Gavin saw was to do the following:

$dx = non_zero_random(-3,3)/10;

If the random or non_zero_random function can give an integer, I have never seen issues with dividing by 10 at that point. list_random is certainly a reasonable alternative in this case, but I have had problems where I've wanted $dx to be a non-zero integer multiple of 0.001 between -1 and 1. In this case

$dx = non_zero_random(-999,999)/1000;

works perfectly.