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.
40 lines
715 B
40 lines
715 B
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#include "crand.h"
|
|
|
|
struct jr_state
|
|
{
|
|
long result;
|
|
struct drand48_data data;
|
|
union {
|
|
unsigned short xsubi[3];
|
|
unsigned int xsubh;
|
|
} st;
|
|
};
|
|
|
|
void _jr_seed(struct jr_state* restrict state, unsigned int with)
|
|
{
|
|
state->st.xsubh = with & JR_MAX;
|
|
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);
|
|
}
|