summaryrefslogtreecommitdiffstats
path: root/include/rand.h
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2019-11-14 12:57:13 -0700
committerTom Rini <trini@konsulko.com>2019-12-02 18:23:07 -0500
commit840ef4d43b69a687660b3722b9c4a8a44a2912f8 (patch)
tree6d54af8d723554926ce4a8724588872bdc5e03aa /include/rand.h
parentc076e5c9b35fc20cdea076e8eae71126e7cadd4f (diff)
downloadu-boot-840ef4d43b69a687660b3722b9c4a8a44a2912f8.tar.gz
u-boot-840ef4d43b69a687660b3722b9c4a8a44a2912f8.tar.xz
u-boot-840ef4d43b69a687660b3722b9c4a8a44a2912f8.zip
common: Move random-number functions into their own header
Create a new rand.h header file and move functions into it, to reduce the size of common.h Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Tom Rini <trini@konsulko.com>
Diffstat (limited to 'include/rand.h')
-rw-r--r--include/rand.h40
1 files changed, 40 insertions, 0 deletions
diff --git a/include/rand.h b/include/rand.h
new file mode 100644
index 0000000000..c9d15f50a1
--- /dev/null
+++ b/include/rand.h
@@ -0,0 +1,40 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * (C) Copyright 2000-2009
+ * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
+ */
+
+#ifndef __RAND_H
+#define __RAND_H
+
+#define RAND_MAX -1U
+
+/**
+ * srand() - Set the random-number seed value
+ *
+ * This can be used to restart the pseudo-random-number sequence from a known
+ * point. This affects future calls to rand() to start from that point
+ *
+ * @seed: New seed
+ */
+void srand(unsigned int seed);
+
+/**
+ * rand() - Get a 32-bit pseudo-random number
+ *
+ * @returns next random number in the sequence
+ */
+unsigned int rand(void);
+
+/**
+ * rand_r() - Get a 32-bit pseudo-random number
+ *
+ * This version of the function allows multiple sequences to be used at the
+ * same time, since it requires the caller to store the seed value.
+ *
+ * @seed value to use, updated on exit
+ * @returns next random number in the sequence
+ */
+unsigned int rand_r(unsigned int *seedp);
+
+#endif