You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
rngxx/src/rng/crand.c

44 lines
779 B

#include <stdlib.h>
#include <string.h>
#include "crand.h"
struct jr_state
{
long result;
struct drand48_data data;
union {
unsigned short xsubi[3];
struct {
unsigned int xsubh : 24;
unsigned char _xsub : 8;
};
unsigned int xsubl;
} st;
};
void _jr_seed(struct jr_state* restrict state, unsigned int with)
{
state->st.xsubh = with;
seed48_r(state->st.xsubi, &state->data);
}
long _jr_proc(struct jr_state* restrict state)
{
jrand48_r(state->st.xsubi, &state->data, &state->result);
return state->result;
}
struct jr_state* _jr_alloc()
{
struct jr_state* bx = aligned_alloc(_Alignof(struct jr_state), sizeof(struct jr_state));
memset(bx, 0, sizeof(struct jr_state));
return bx;
}
void _jr_free(struct jr_state* restrict state)
{
free(state);
}