/usr/games/random bug?
James R. Van Artsalen
james at jrv.org
Mon Dec 20 17:13:50 PST 2004
5-stable "/usr/games/random -e 99" seems to always return 0, which makes
it very predictable.
5.2.1 does this too. But i386 4.x seems to work as expected (an exit
value between 0 and 98 inclusive).
The source code line in question is
return (int)((denom * random()) / LONG_MAX);
the assembler code is
.p2align 3
.LC17:
.long 0
.long 1006632960
call random
cvtsi2sdq %rax, %xmm0
mulsd 24(%rsp), %xmm0
mulsd .LC17(%rip), %xmm0
cvttsd2si %xmm0, %eax
jmp .L1
I'm not familiar enough with IEEE fp rules or amd64 fp coding to say why
this doesn't work, nor if this source code is even reasonable.
More information about the freebsd-amd64
mailing list