[hackers] [scc] [libc] Add rand() || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Thu, 23 Feb 2017 19:25:52 +0100 (CET)

commit 5322cbec9cd0fc0212a87e4b24ff73fa28133c94
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Thu Feb 23 19:25:08 2017 +0100
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Thu Feb 23 19:25:08 2017 +0100

    [libc] Add rand()

diff --git a/libc/include/bits/amd64-sysv/arch/stdlib.h b/libc/include/bits/amd64-sysv/arch/stdlib.h
index c983430..94941c0 100644
--- a/libc/include/bits/amd64-sysv/arch/stdlib.h
+++ b/libc/include/bits/amd64-sysv/arch/stdlib.h
_AT_@ -11,7 +11,6 @@ typedef unsigned long size_t;
 
 #define EXIT_FAILURE 1
 #define EXIT_SUCCESS 0
-#define RAND_MAX 32767
 
 #ifndef _WCHAR_T
 typedef int wchar_t;
diff --git a/libc/include/bits/i386-sysv/arch/stdlib.h b/libc/include/bits/i386-sysv/arch/stdlib.h
index c983430..94941c0 100644
--- a/libc/include/bits/i386-sysv/arch/stdlib.h
+++ b/libc/include/bits/i386-sysv/arch/stdlib.h
_AT_@ -11,7 +11,6 @@ typedef unsigned long size_t;
 
 #define EXIT_FAILURE 1
 #define EXIT_SUCCESS 0
-#define RAND_MAX 32767
 
 #ifndef _WCHAR_T
 typedef int wchar_t;
diff --git a/libc/include/bits/qbe/arch/stdlib.h b/libc/include/bits/qbe/arch/stdlib.h
index c983430..94941c0 100644
--- a/libc/include/bits/qbe/arch/stdlib.h
+++ b/libc/include/bits/qbe/arch/stdlib.h
_AT_@ -11,7 +11,6 @@ typedef unsigned long size_t;
 
 #define EXIT_FAILURE 1
 #define EXIT_SUCCESS 0
-#define RAND_MAX 32767
 
 #ifndef _WCHAR_T
 typedef int wchar_t;
diff --git a/libc/include/bits/z80/arch/stdlib.h b/libc/include/bits/z80/arch/stdlib.h
index 5006886..11f9b16 100644
--- a/libc/include/bits/z80/arch/stdlib.h
+++ b/libc/include/bits/z80/arch/stdlib.h
_AT_@ -11,7 +11,6 @@ typedef unsigned size_t;
 
 #define EXIT_FAILURE 1
 #define EXIT_SUCCESS 0
-#define RAND_MAX 32767
 
 #ifndef _WCHAR_T
 typedef long wchar_t;
diff --git a/libc/include/stdlib.h b/libc/include/stdlib.h
index 130be05..2b3052b 100644
--- a/libc/include/stdlib.h
+++ b/libc/include/stdlib.h
_AT_@ -5,6 +5,7 @@
 #include <arch/stdlib.h>
 
 #define MB_CUR_MAX 1
+#define RAND_MAX 32767
 
 typedef struct {
         int quot, rem;
diff --git a/libc/src/rand.c b/libc/src/rand.c
new file mode 100644
index 0000000..803b9a0
--- /dev/null
+++ b/libc/src/rand.c
_AT_@ -0,0 +1,18 @@
+/* See LICENSE file for copyright and license details. */
+
+#include <stdlib.h>
+
+static int next;
+
+void
+srand(unsigned seed)
+{
+ next = seed;
+}
+
+int
+rand(void) /* RAND_MAX assumed to be 32767. */
+{
+ next = next * 1103515245 + 12345;
+ return (unsigned)(next/65536) % 32768;
+}
Received on Thu Feb 23 2017 - 19:25:52 CET

This archive was generated by hypermail 2.3.0 : Thu Feb 23 2017 - 19:36:19 CET