]> git.ipfire.org Git - thirdparty/mlmmj.git/commitdiff
Makes random number generation more efficient by only seeding the
authorBen Schmidt <none@none>
Fri, 30 Jul 2010 14:25:36 +0000 (00:25 +1000)
committerBen Schmidt <none@none>
Fri, 30 Jul 2010 14:25:36 +0000 (00:25 +1000)
generator once

ChangeLog
src/random-int.c

index 6a2aafe10559bc0b517642719a628f0635f5e132..535072f27d0325cbe629391e339f04509c61adff 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,5 @@
+ o Make random number generation more efficient by only seeding the
+   generator once
  o Added feature to notify users when their posts are moderated
  o Fixed documentation regarding silent subscription, and added
    ability to silently subscribe
index b8db32c467227d82f000ba9e550aa08548cab0dc..de143816a60e3d10cca6978da4324c92039295d4 100644 (file)
 
 int random_int()
 {
+       static int init = 0;
        unsigned int seed;
        int devrandom;
        unsigned char ch;
 
+       if (init) return rand();
+
        seed = (unsigned int)time(NULL);
 
        devrandom = open("/dev/urandom", O_RDONLY);
@@ -53,6 +56,7 @@ int random_int()
        }
 
        srand(seed);
+       init = 1;
 
        return rand();
 }