diff options
author | Daniel Balla <dballa@inf.u-szeged.hu> | 2017-11-06 11:31:22 +0100 |
---|---|---|
committer | Dániel Bátyai <dbatyai@inf.u-szeged.hu> | 2017-11-06 11:31:22 +0100 |
commit | 3de6c7ec7a7aaef3347dbdda5d46a1216ae1d6bc (patch) | |
tree | 8e39fe4e6e1a0de929c1662c2da582d518c03b8f /jerry-libc | |
parent | 8ae659227e02ecbb5241c95c20b0e750c319150e (diff) |
Fix jerry-libc's srand function (#2068)
The previous implementation of srand was wrong in jerry-libc.
It set all 4 values to the seed, not modifying anything in them, causing random values to be repeated pretty often.
This approach fixes the mentioned issue.
JerryScript-DCO-1.0-Signed-off-by: Daniel Balla dballa@inf.u-szeged.hu
Diffstat (limited to 'jerry-libc')
-rw-r--r-- | jerry-libc/jerry-libc.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/jerry-libc/jerry-libc.c b/jerry-libc/jerry-libc.c index 65119505..54002d0a 100644 --- a/jerry-libc/jerry-libc.c +++ b/jerry-libc/jerry-libc.c @@ -276,10 +276,14 @@ rand (void) void srand (unsigned int seed) /**< new seed */ { - libc_random_gen_state[0] = - libc_random_gen_state[1] = - libc_random_gen_state[2] = - libc_random_gen_state[3] = seed; + libc_random_gen_state[0] = (uint32_t) ((seed * 14316555781) + + (seed * 1183186591) + + (seed * 622729787) + + (seed * 338294347)); + + libc_random_gen_state[1] = 842502087; + libc_random_gen_state[2] = 3579807591; + libc_random_gen_state[3] = 273326509; } /* srand */ /** |