WeBWorK Problems

Generate Different Random Numbers

Re: Generate Different Random Numbers

by Rob Owen -
Number of replies: 0
I actually wrote an extensive routine that will let you choose random variables, in a systematized way, to defeat that sort of thing. The invocation is kind of nightmarish -- I chose it the way I did for a reason, although I'm no longer convinced this was the right way -- but if you don't mind cutting and pasting you can do something like this:

randomListByRef( sub { my $arr; my ($C,$P,$R) = @_;
return ( byOr($arr, @_) && gcd($P,$R) == 1 ); },
[~~$aConst, 2, 7], [~~$aPower, 2, 7], [~~$aRoot, 2, 7] );

which would let you pick three new numbers $aConst, $aPower and $aRoot from 2-7 such that a) at least one of them is different from their original/current value [that's the byOr function call] and b) aPower and aRoot are relatively prime [that's the gcd part]. If anyone's interested, I'd be happy to provide the code for it.

[The random loop terminates stochastically, btw; in general, I've found that if the right combination of random numbers can't be found in 100 guesses, I probably programmed the condition wrong.]