Random number generation with global and per-stream APIs.
Random number generation with global and per-stream APIs.Banjo provides two random number APIs:
Use the global API for quick prototyping. Use PCG32 when you need:
return (hi << 32) | lo;
}
int main(int argc, char* argv[]) {
(void)argc; (void)argv;
for (size_t i = 0; i < 5; ++i) {
}
for (size_t i = 0; i < 5; ++i) {
}
for (size_t i = 0; i < 3; ++i) {
}
bj_info(
"\tseeded with time, seq=54:");
for (size_t i = 0; i < 3; ++i) {
}
bj_info(
"\tseeded with time, seq=55 (independent):");
for (size_t i = 0; i < 3; ++i) {
}
bj_info(
"\tu64 from two draws: 0x%016llx", (
unsigned long long)x);
return 0;
}
#define bj_info(...)
Log a message using the BJ_LOG_INFO level.
Definition log.h:105
void bj_seed_pcg32(struct bj_pcg32 *generator, uint64_t seed, uint64_t seq)
Set the generator state from seed and sequence.
uint32_t bj_min_pcg32(void)
Smallest possible value returned by the generator.
void bj_discard_pcg32(struct bj_pcg32 *generator, uint64_t z)
Advance the generator state by z steps.
uint32_t bj_max_pcg32(void)
Largest possible value returned by the generator.
void bj_srand(unsigned int seed)
Seed the standard PRNG.
int bj_rand(void)
Generate a pseudo-random integer in [0, BJ_RAND_MAX].
uint32_t bj_next_pcg32(struct bj_pcg32 *generator)
Advance the generator and return the next 32-bit value.
PCG32 generator state.
Definition random.h:46
uint64_t bj_get_time(void)
Get the current system time in seconds since the Unix epoch.
Logging utility functions.
Portable main substitution and application callback facilities.
static uint64_t pcg32_u64(bj_pcg32 *g)
Definition random.c:23
Pseudo-random number generation API.
String utility functions.
Header file for time manipulation utilities.