Make alternative sigcontextpath a little more generic.
[AROS.git] / compiler / clib / rand.c
blob2f53bfa8bf26ec20071f2f37f82df9ec56549317
1 /*
2 Copyright © 1995-2012, The AROS Development Team. All rights reserved.
3 $Id$
5 ANSI C functions rand() and srand().
6 */
8 #include "__arosc_privdata.h"
10 #include <aros/symbolsets.h>
12 /*****************************************************************************
14 NAME */
15 #include <stdlib.h>
17 int rand (
19 /* SYNOPSIS */
20 void)
22 /* FUNCTION
23 A random number generator.
25 INPUTS
26 None.
28 RESULT
29 A pseudo-random integer between 0 and RAND_MAX.
31 NOTES
33 EXAMPLE
35 BUGS
37 SEE ALSO
38 srand()
40 INTERNALS
42 ******************************************************************************/
44 struct aroscbase *aroscbase = __GM_GetBase();
46 aroscbase->acb_srand_seed = aroscbase->acb_srand_seed * 1103515245 + 12345;
48 return aroscbase->acb_srand_seed % RAND_MAX;
49 } /* rand */
52 /*****************************************************************************
54 NAME */
55 #include <stdlib.h>
57 void srand (
59 /* SYNOPSIS */
60 unsigned int seed)
62 /* FUNCTION
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.
67 INPUTS
68 seed - New start value
70 RESULT
71 None.
73 NOTES
74 One seed value per arosc.library is kept which normally corresponds
75 with per task.
77 EXAMPLE
79 BUGS
81 SEE ALSO
82 rand()
84 INTERNALS
86 ******************************************************************************/
88 struct aroscbase *aroscbase = __GM_GetBase();
90 aroscbase->acb_srand_seed = seed;
91 } /* srand */
93 static int __rand_seedinit(struct aroscbase *aroscbase)
95 aroscbase->acb_srand_seed = 1;
97 return 1;
100 ADD2OPENLIB(__rand_seedinit, 0);