[SLOF] [PATCH 3/7] libc: Add srand() call

Stefan Berger stefanb at linux.vnet.ibm.com
Tue Dec 22 02:46:50 AEDT 2015


On 12/17/2015 03:18 PM, Thomas Huth wrote:
> Needed for seeding the state of the pseudo-random number generator.
>
> Signed-off-by: Thomas Huth <thuth at redhat.com>
> ---
>   lib/libc/include/stdlib.h | 1 +
>   lib/libc/stdlib/rand.c    | 5 +++++
>   2 files changed, 6 insertions(+)
>
> diff --git a/lib/libc/include/stdlib.h b/lib/libc/include/stdlib.h
> index dff57f5..5e0eda9 100644
> --- a/lib/libc/include/stdlib.h
> +++ b/lib/libc/include/stdlib.h
> @@ -29,5 +29,6 @@ unsigned long int strtoul(const char *nptr, char **endptr, int base);
>   long int strtol(const char *nptr, char **endptr, int base);
>   
>   int rand(void);
> +void srand(unsigned int seed);
>   
>   #endif
> diff --git a/lib/libc/stdlib/rand.c b/lib/libc/stdlib/rand.c
> index 98c7e6d..39f5a9a 100644
> --- a/lib/libc/stdlib/rand.c
> +++ b/lib/libc/stdlib/rand.c
> @@ -22,3 +22,8 @@ rand(void)
>   
>   	return ((unsigned int) (_rand >> 16) & RAND_MAX);
>   }
> +
> +void srand(unsigned int seed)
> +{
> +	_rand = seed;
> +}
Reviewed-by: Stefan Berger <stefanb at linux.vnet.ibm.com>



More information about the SLOF mailing list