- Use
xoshiro256++ PRNG to generate random numbers in C with a header-only library.
- Write random bytes to a binary file using the CLI tool.
Header-Only Library
#define RANDWRITE_IMPLEMENTATION
#include "randxoshiro.h"
#include <stdio.h>
#include <time.h>
int main(void)
{
xo_state state = {0};
srand_xo(&state, time(0)); // prefer to use stronger seed than time(0)
printf("Random number: %lld \n", (int64_t)rand_xo(&state));
return 0;
}
- Build with command below or run
rwcli.bat
gcc rwcli.c -o rwcli.exe -O3 -s
- To write 10 random 64 bit numbers (80 random bytes) to specified path
myfileee, run:
- The CLI tool currently doesn't write "numbers" to a file, it writes randomized bytes directly. This allows easy reinterpration of the same random data e.g. as u64's or as i64's as u32's.
- Xoshiro256++ PRNG's state is initialized using
splitmax64 PRNG to satisfy xoshiro256++ no-zero's requirement. The splitmax64 PRNG's state itself is currently only seeded with time(0) in the CLI demo.
- When the CLI program receives a command to e.g. write
100 random numbers to a file, it internally malloc's 100 * 8 bytes to create a buffer that can hold the requested amount of 64 bit numbers.
- Add "number" writing instead of byte writing, specified via flag.
- Add float writing support. (culling invalid floats?)
- Initialize splitmax64 with a stronger seed.