hush: replace flag bytes in struct o_string with bit flags
[oweals/busybox.git] / shell / random.c
index cca9d120dfcaee290a97a95c319d68d2da6785f4..853ab085a22c1ee5b3dfae79d88fc9ac9f56f225 100644 (file)
@@ -4,7 +4,7 @@
  *
  * Copyright (C) 2009 Denys Vlasenko
  *
- * Licensed under GPLv2, see file LICENSE in this tarball for details.
+ * Licensed under GPLv2, see file LICENSE in this source tree.
  */
 #include "libbb.h"
 #include "random.h"
@@ -20,6 +20,13 @@ next_random(random_t *rnd)
 
        uint32_t t;
 
+       if (UNINITED_RANDOM_T(rnd)) {
+               /* Can use monotonic_ns() for better randomness but for now
+                * it is not used anywhere else in busybox... so avoid bloat
+                */
+               INIT_RANDOM_T(rnd, getpid(), monotonic_us());
+       }
+
        /* LCG has period of 2^32 and alternating lowest bit */
        rnd->LCG = 1664525 * rnd->LCG + 1013904223;
        /* Galois LFSR has period of 2^32-1 = 3 * 5 * 17 * 257 * 65537 */