Compare commits
2 Commits
32ade1777f
...
a0b1d289a7
Author | SHA1 | Date | |
---|---|---|---|
a0b1d289a7 | |||
fec1dc68b5 |
40
src/misc.c
40
src/misc.c
@@ -12,6 +12,9 @@
|
||||
*/
|
||||
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <bug.h>
|
||||
|
||||
#include "chessdefs.h"
|
||||
|
||||
@@ -110,3 +113,40 @@ double clock_elapsed_sec(mclock_t *clock)
|
||||
{
|
||||
return (double) clock_elapsed_μs(clock) / (double) MICRO_IN_SEC;
|
||||
}
|
||||
|
||||
static u64 rand_seed = 1ull;
|
||||
|
||||
/**
|
||||
* rand_init() - initialize random generator seed.
|
||||
* @seed: u64, the random generator seed.
|
||||
*
|
||||
* No change is made is performed if If @seed is zero. By default, @seed is
|
||||
* 1.
|
||||
* This seed is used by rand64().
|
||||
*/
|
||||
void rand_init(u64 seed)
|
||||
{
|
||||
if (seed)
|
||||
rand_seed = seed;
|
||||
}
|
||||
|
||||
/**
|
||||
* rand64() - get a random number, xorshift method.
|
||||
*
|
||||
* Source:
|
||||
* https://en.wikipedia.org/wiki/Xorshift#xorshift*
|
||||
* We do not want true random numbers, like those offered by getrandom(2), as we
|
||||
* need to be able to get predictable results.
|
||||
* Note: For predictable results in MT, we should use separate seeds.
|
||||
*
|
||||
* @return: a 64 bits random number.
|
||||
*/
|
||||
u64 rand64(void)
|
||||
{
|
||||
bug_on(rand_seed == 0ull);
|
||||
|
||||
rand_seed ^= rand_seed >> 12;
|
||||
rand_seed ^= rand_seed << 25;
|
||||
rand_seed ^= rand_seed >> 27;
|
||||
return rand_seed * 0x2545f4914f6cdd1dull;
|
||||
}
|
||||
|
@@ -362,17 +362,23 @@ int main(int __unused ac, __unused char**av)
|
||||
/* to run first test only */
|
||||
// exit(0);
|
||||
}
|
||||
if (run & 1)
|
||||
if (run & 1) {
|
||||
if (!res[0].ms)
|
||||
res[0].ms = 1;
|
||||
printf("total perft %'lums %'lums lps=%'lu min=%'lu max=%'lu (skipped %d)\n",
|
||||
res[0].count, res[0].ms,
|
||||
res[0].count * 1000l / res[0].ms,
|
||||
res[0].minlps, res[0].maxlps,
|
||||
res[0].skipped);
|
||||
if (run & 2)
|
||||
}
|
||||
if (run & 2) {
|
||||
if (!res[1].ms)
|
||||
res[1].ms = 1;
|
||||
printf("total perft2 %'lums %'lums lps=%'lu min=%'lu max=%'lu (skipped %d)\n",
|
||||
res[1].count, res[1].ms,
|
||||
res[1].count * 1000l / res[1].ms,
|
||||
res[1].minlps, res[1].maxlps,
|
||||
res[1].skipped);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user