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

Hi

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.

>M:=600;

>R1:=rand(0..1):   R2:=() -> 2*R1()-1:       
>for i from 1 to M do
    f[i]:=R2()*rand()/10.^12:
  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...