This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
bug: rand() not initialized
- From: "Joshua Nekl" <jnekl at zilog dot com>
- To: <newlib at sources dot redhat dot com>
- Date: Wed, 1 Oct 2008 16:14:12 -0700
- Subject: bug: rand() not initialized
newlib/libc/stdlib/rand.c
rand() calls _REENT_CHECK_RAND48
newlib/libc/include/sys/reent.h
_REENT_CHECK_RAND48 calls _REENT_CHECK with _REENT_INIT_RAND48
_REENT_CHECK calls _REENT_INIT_RAND48 after malloc(struct
_rand48)
_REENT_INIT_RAND48 inits struct _rand48 *_r48 members except
_next_rand
rand() calls _REENT_RAND_NEXT
_REENT_RAND_NEXT returns unnitialized _next_rand
I know an uninitialized pseudo-random number may seem unimportant, but
...
1) repeated runs of the application should return the same pseudo-random
number
in order for test results to be repeatable.
2) I'm using a 4-state simulator (verilog).
Since this variable is not initialized, it returns X's in my
simulation.
X's multiplied by X's result in X's, and my simulation barfs.
Workaround -> call srand(1) first.
Regards, Josh