Skip to main content
deleted 68 characters in body
Source Link

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)

To get a range of [-n , n] from drand48() which has initial range of [1 , 0] do the following:

drand48() = [0 , 1] But we want= [-n , n] (min) (max)

can we add/multiply something to min{drand48()} to make it equal to (-n)? Yes.

min{drand48()} + (-n) = 0 + (-n) = (-n)

but what about max? max{drand48()} + (-n) = 1 + (-n)  != n

but can something be multiplied to 1 ,ie, max{drand48()} ? Yes. (2n)*max{drand48()} + (-n) = (2n)*1 + (-n) = n

hence c = pd + q min(c) = pmin(d) + q max(c) = p*max(d) + q

where d = drand48()  p = 2n q = (-n)

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 we want= [-n , n]

can we add/multiply something to 0 to make it equal to -n? Yes.

= 0 + (-n)

= -n

But what about max?

= 1 + (-n) 

!= n (oops!)

But can something be multiplied to 1? Yes.

= (2n)*1 + (-n)

= n

generalising c = p*d + q

min(c) = p*min(d) + q

max(c) = p*max(d) + q

where d = drand48() ,p = 2n , q = (-n)

Source Link

To get a range of [-n , n] from drand48() which has initial range of [1 , 0] do the following:

drand48() = [0 , 1] But we want= [-n , n] (min) (max)

can we add/multiply something to min{drand48()} to make it equal to (-n)? Yes.

min{drand48()} + (-n) = 0 + (-n) = (-n)

but what about max? max{drand48()} + (-n) = 1 + (-n) != n

but can something be multiplied to 1 ,ie, max{drand48()} ? Yes. (2n)*max{drand48()} + (-n) = (2n)*1 + (-n) = n

hence c = pd + q min(c) = pmin(d) + q max(c) = p*max(d) + q

where d = drand48() p = 2n q = (-n)