]> pd.if.org Git - pdclib/blobdiff - functions/stdlib/rand.c
PDCLib includes with quotes, not <>.
[pdclib] / functions / stdlib / rand.c
index abe58f6fd9e2bf17ccd5adccfce5326d8138f1a7..1e8f3cd789b2542ba0e7ab78c969cb412ff325c7 100644 (file)
@@ -1,28 +1,33 @@
-/* ----------------------------------------------------------------------------
- * $Id$
- * ----------------------------------------------------------------------------
- * Public Domain C Library - http://pdclib.sourceforge.net
- * This code is Public Domain. Use, modify, and redistribute at will.
- * --------------------------------------------------------------------------*/
+/* rand( void )
 
-int rand( void ) { /* TODO */ };
-void srand( unsigned int seed ) { /* TODO */ };
+   This file is part of the Public Domain C Library (PDCLib).
+   Permission is granted to use, modify, and / or redistribute at will.
+*/
+
+#include <stdlib.h>
 
-/* PDPC code - unreviewed
-static unsigned long myseed = 1;
+#ifndef REGTEST
 
-void srand(unsigned int seed)
+int rand( void )
 {
-    myseed = seed;
-    return;
+    _PDCLIB_seed = _PDCLIB_seed * 1103515245 + 12345;
+    return (int)( _PDCLIB_seed / 65536 ) % 32768;
 }
 
-int rand(void)
+#endif
+
+#ifdef TEST
+#include "_PDCLIB_test.h"
+
+int main( void )
 {
-    int ret;
-    
-    myseed = myseed * 1103515245UL + 12345;
-    ret = (int)((myseed >> 16) & 0x8fff);
-    return (ret);
+    int rnd1, rnd2;
+    TESTCASE( ( rnd1 = rand() ) < RAND_MAX );
+    TESTCASE( ( rnd2 = rand() ) < RAND_MAX );
+    srand( 1 );
+    TESTCASE( rand() == rnd1 );
+    TESTCASE( rand() == rnd2 );
+    return TEST_RESULTS;
 }
-*/
+
+#endif