Question: How do I generate random number between -x and +x?


I need help to write a procedure that uses Maple`s built-in rand() - function to generate uniform random floating point numbers between -r and r, where r is an input parameter of the procedure.


>R1:=rand(0..1):   R2:=() -> 2*R1()-1:       
>for i from 1 to M do
  end do:

With this procedure I get random floating point numbers (+/-), but I can`t figure out how to generate numbers between +/- a parameter (in this case r).

If anyone could help me understand how to get this to work I would be very gratefull.

Please Wait...