[PATCH 04/11] include support for a simple pseudo number generator

Peter Korsgaard jacmet at sunsite.dk
Tue Jun 15 05:39:39 EDT 2010


>>>>> "Sascha" == Sascha Hauer <s.hauer at pengutronix.de> writes:

 Sascha> Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
 Sascha> ---
 Sascha>  include/random.h |    7 +++++++
 Sascha>  lib/Makefile     |    1 +
 Sascha>  lib/random.c     |   22 ++++++++++++++++++++++
 Sascha>  3 files changed, 30 insertions(+), 0 deletions(-)
 Sascha>  create mode 100644 include/random.h
 Sascha>  create mode 100644 lib/random.c

 Sascha> diff --git a/lib/random.c b/lib/random.c
 Sascha> new file mode 100644
 Sascha> index 0000000..25315e7
 Sascha> --- /dev/null
 Sascha> +++ b/lib/random.c
 Sascha> @@ -0,0 +1,22 @@
 Sascha> +#include <common.h>
 Sascha> +#include <random.h>
 Sascha> +
 Sascha> +static int random_seed;
 Sascha> +
 Sascha> +static unsigned char rand(void)
 Sascha> +{
 Sascha> +	random_seed = random_seed * 1103515245 + 12345;
 Sascha> +	return (unsigned char)(random_seed / 65536) % 256;
 Sascha> +}

Any reason to not make this public and return int instead similar to
rand(3)?

We could presumably simply do:

#define RAND_MAX 255

And to be completely correct, these prototypes should be in stdlib.h
instead.

-- 
Bye, Peter Korsgaard



More information about the barebox mailing list