# Generate random numbers with conditions using maxima (cas)

I want to generate (multiple) random numbers from a given number class with extra conditions. (for automatic generation of exercises)

e.g.:

• generate "a" out of natural Numbers which are dividible by three
• generate "b" which is a rational number but not natural number
• generate "c" and "d" which are both prime numbers and "d" is at least twice as big as "c"

ideally also:

• generate "f" as a polynomyal function of grade 2

My plan is to write a little script that will be then run multiple times from maxima and maxima outputs new tasks (with their solutions) every time.

my idea (pseudocode)

a := random(natural_numbers) | rest(a / 3) = 0
solution := 1/3 + 2/a


and this would output an "a" that I can use to build the exercise as well as a "solution" that i can check against.

• you cant generate random natural uniformly distributed or unbounded because there is computational limitation in the number of ciphers a number can achieve. The best you can do is use a random number generator in a bounded set of naturals, by example choosing naturals from 1 to 100. Anyway this doen't seems the best stackexchange forum for this question – Masacroso Nov 18 '18 at 0:59