Fixing #100 (continued): 31 bit random number generator with static seed (Android)
authorEdouard Tisserant
Tue, 12 Jul 2016 12:29:10 +0200
changeset 841bb25b36f52d6
parent 840 3d5e68bfc548
child 842 baab4fe95591
child 843 b1695eef237b
Fixing #100 (continued): 31 bit random number generator with static seed (Android)
src/platform_unix.c
     1.1 --- a/src/platform_unix.c	Tue Jul 12 12:07:46 2016 +0200
     1.2 +++ b/src/platform_unix.c	Tue Jul 12 12:29:10 2016 +0200
     1.3 @@ -52,11 +52,16 @@
     1.4  
     1.5  long int random(void)
     1.6  {
     1.7 -    time_t t = time(NULL);
     1.8 +    static bool seeded = false;
     1.9      static unsigned short xsubi[3];
    1.10 -    xsubi[0] = ((unsigned short *)t)[0];
    1.11 -    xsubi[1] = ((unsigned short *)t)[1];
    1.12 -    xsubi[2] = ((unsigned short *)t)[2];
    1.13 +    if(!seeded)
    1.14 +    {
    1.15 +        time_t t = time(NULL);
    1.16 +        xsubi[0] = ((unsigned short *)t)[0];
    1.17 +        xsubi[1] = ((unsigned short *)t)[1];
    1.18 +        xsubi[2] = ((unsigned short *)t)[2];
    1.19 +        seeded = true;
    1.20 +    }
    1.21  
    1.22      return nrand48(xsubi);
    1.23  }