even if you don't want to use a self defined precission you could try this
perl -Mposix -E" say rand(1+1/2**47) for 1..20"
So why 47?
Just try and error on my system
C:\Windows\system32>perl -E" say 1+1/2**47;" + 1.00000000000001 C:\Windows\system32>perl -E" say 1+1/2**48;" 1
I'm too lazy to figure out how exactly the limits of the mantissa is used internally and where the caveats are.
And taking the rounding errors in these into assumption this shouldn't matter much. (as BUK mentioned under windows before 5.20 rand is limted to 15 bits only.)
The practical value of this is too small to justify more elaboration.
or alternatively to avoid floats and rounding errors
C:\Windows\system32>perl -E"$r=int rand(1e15+1); say $r==1e15 ? 1 : sp +rintf '0.%015s', $r" 0.176483154296875
Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!
In reply to Re^5: inclusive rand
by LanX
in thread inclusive rand
by msh210
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |