To get a range of [-n , n] from drand48() which has initial range of [1 , 0] do the following:
rane = [min , max]
drand48() = [0 , 1] But
But we want= [-n , n] (min) (max)
can we add/multiply something to min{drand48()}0 to make it equal to (-n)? Yes.
min{drand48()} + (-n) == 0 + (-n) =
= (-n)
butBut what about max? max{drand48()} + (-n) =
= 1 + (-n)
!= n (oops!)
butBut can something be multiplied to 1 ,ie, max{drand48()} ? Yes. (2n)*max{drand48()} + (-n) =
= (2n)*1 + (-n) =
= n
hencegeneralising c = pd + q min(c) = pminp*d + q
min(c) = p*min(d) + q max
max(c) = p*max(d) + q
where d = drand48() ,p = 2n q , q = (-n)