random number including 1 - i.e. [0,1]
gatti at dsdata.it
Wed Jun 10 09:22:14 CEST 2009
On 10 Giu, 06:23, Esmail <ebo... at hotmail.com> wrote:
> Here is part of the specification of an algorithm I'm implementing that
> shows the reason for my original query:
> vid = w * vid + c1 * rand( ) * ( pid – xid ) + c2 * Rand( ) * (pgd –xid ) (1a)
> xid = xid + vid (1b)
> where c1 and c2 are two positive constants,
> rand() and Rand() are two random functions in the range [0,1],
> and w is the inertia weight.
1) I second John Yeung's suggestion: use random integers between 0 and
N-1 or N inclusive and divide by N to obtain a maximum value of (N-1)/
N or 1 as you prefer. Note that N doesn't need to be very large.
2) I'm not sure a pseudo-closed range is different from a pseudo-open
one. You are perturbing vid and xid by random amounts, scaled by
arbitrary coefficients c1 and c2: if you multiply or divide these
coefficients by (N-1)/N the minimum and maximum results for the two
choices can be made identical up to floating point mangling.
More information about the Python-list