in reply to inclusive rand
If you multiply rand by 101, int it, then divide by 100, you'll get all possible (2-decimal place) values between 0 and 1 inclusive with 'equal probability':
If you need 3 decimal places, use 1000*int( rand *1001 ); and for 4: 10000*int( rand * 10001 ) etc. Corrected. Thanks to pryrt.
If you need 3 decimal places, use int( rand *1001 )/1000; and for 4: int( rand * 10001 )/10000 etc.
(But beware the number of bits available in the rand() you use. On Windows, pre-5.20something, perl's rand() only has 15-bits. )
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: inclusive rand
by pryrt (Abbot) on Mar 13, 2017 at 15:31 UTC | |
by BrowserUk (Patriarch) on Mar 13, 2017 at 18:01 UTC | |
Re^2: inclusive rand
by msh210 (Monk) on Mar 13, 2017 at 14:24 UTC |