File tree 2 files changed +14
-14
lines changed
2 files changed +14
-14
lines changed Original file line number Diff line number Diff line change 5
5
#include <unistd.h>
6
6
#include <sys/resource.h>
7
7
8
- /*
9
- * Return a pseudo-random number in the range 0 .. n-1
10
- */
11
- // FIXME: drand48 doesn't provide enough random bits for 64bit LPC int.
12
- long random_number (long n )
13
- {
14
- static char called = 0 ;
8
+ #include <random>
15
9
16
- if (!called ) {
17
- time_t tim ;
10
+ // Returns a pseudo-random number in the range 0 .. n-1
11
+ int64_t random_number (int64_t n )
12
+ {
13
+ static bool called = 0 ;
14
+ static std ::mt19937_64 engine ;
18
15
19
- time (& tim );
20
- srand48 (tim );
16
+ if (!called ) {
17
+ std ::random_device rd ;
18
+ engine .seed (rd ());
21
19
called = 1 ;
22
- } /* endif */
23
- return (long )(drand48 () * n );
20
+ }
21
+
22
+ std ::uniform_int_distribution < int64_t > dist (0 , n - 1 );
23
+ return dist (engine );
24
24
}
25
25
26
26
/*
Original file line number Diff line number Diff line change 5
5
* port.c
6
6
*/
7
7
#ifndef _FUNC_SPEC_
8
- long random_number (long );
8
+ int64_t random_number (int64_t );
9
9
long get_current_time (void );
10
10
const char * time_string (time_t );
11
11
void get_usec_clock (long * , long * );
You can’t perform that action at this time.
0 commit comments