2 Copyright © 1995-2016, The AROS Development Team. All rights reserved.
5 C99 functions rand() and srand().
8 #include "__stdc_intbase.h"
10 #include <aros/symbolsets.h>
12 /*****************************************************************************
23 A random number generator.
29 A pseudo-random integer between 0 and RAND_MAX.
42 ******************************************************************************/
44 struct StdCIntBase
*StdCBase
= (struct StdCIntBase
*)__aros_getbase_StdCBase();
46 StdCBase
->srand_seed
= StdCBase
->srand_seed
* 1103515245 + 12345;
48 return ((StdCBase
->srand_seed
>> 16) % RAND_MAX
);
52 /*****************************************************************************
63 Set the starting value for the random number generator rand()
64 If a seed value is set to a value the same stream of pseudo-random
65 numbers will be generated by rand() for the same seed value.
68 seed - New start value
74 One seed value per stdc.library is kept which normally corresponds
86 ******************************************************************************/
88 struct StdCIntBase
*StdCBase
= (struct StdCIntBase
*)__aros_getbase_StdCBase();
90 StdCBase
->srand_seed
= seed
;
93 static int __rand_seedinit(struct StdCIntBase
*StdCBase
)
95 // use Xorshift with the suggested coefficients by Marsaglia for
96 // a 32-bit generator (13, 17, 5) to set our initial seed.
97 StdCBase
->srand_seed
= time(NULL
);
98 StdCBase
->srand_seed
^= StdCBase
->srand_seed
>> 13; // a
99 StdCBase
->srand_seed
^= StdCBase
->srand_seed
<< 17; // b
100 StdCBase
->srand_seed
^= StdCBase
->srand_seed
>> 5; // c
105 ADD2OPENLIB(__rand_seedinit
, 0);