parent
7bd7964d98
commit
5ac7fc5e11
@ -0,0 +1,39 @@
|
||||
#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);
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
#include <rng.h>
|
||||
|
||||
#include "crand.h"
|
||||
|
||||
namespace rng
|
||||
{
|
||||
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
#ifndef _CRAND_H
|
||||
#define _CRAND_H
|
||||
|
||||
#include <common.h>
|
||||
|
||||
#define JR_MAX (UINT32_MAX >> 8)
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct jr_state;
|
||||
|
||||
//TODO: make all these functions visibility("internal")
|
||||
|
||||
void _jr_seed(struct jr_state* restrict state, unsigned int with);
|
||||
long _jr_proc(struct jr_state* restrict state);
|
||||
struct jr_state* _jr_alloc();
|
||||
void _jr_free(struct jr_state* restrict state);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
Loading…
Reference in new issue