folly: fix github ci tests on macos arm
[hiphop-php.git] / hphp / neo / neo_rand.c
blob00b09a89e3b4375447b5fe9b310ff3702e435997
1 /*
2 * Copyright 2001-2004 Brandon Long
3 * All Rights Reserved.
5 * ClearSilver Templating System
7 * This code is made available under the terms of the ClearSilver License.
8 * http://www.clearsilver.net/license.hdf
12 #include "cs_config.h"
14 #include <stdlib.h>
15 #include <stdio.h>
16 #include <time.h>
17 #include "neo_misc.h"
18 #include "neo_rand.h"
20 static int RandomInit = 0;
22 void neo_seed_rand (long int seed)
24 #ifdef HAVE_DRAND48
25 srand48(seed);
26 #elif HAVE_RANDOM
27 srandom(seed);
28 #else
29 srand(seed);
30 #endif
31 RandomInit = 1;
34 int neo_rand (int max)
36 int r;
38 if (RandomInit == 0)
40 neo_seed_rand (time(NULL));
42 #ifdef HAVE_DRAND48
43 r = drand48() * max;
44 #elif HAVE_RANDOM
45 r = random() * max;
46 #else
47 r = rand() * max;
48 #endif
49 return r;