rng.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2011 Equinor ASA, Norway.
3
4 The file 'rng.h' is part of ERT - Ensemble based Reservoir Tool.
5
6 ERT is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 ERT is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE.
14
15 See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
16 for more details.
17*/
18
19#ifndef ERT_RNG_H
20#define ERT_RNG_H
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25#include <stdio.h>
26
28
29
30typedef enum {
31 INIT_DEFAULT = 0, /* The rng is initialized with the default seed values. */
32 INIT_CLOCK = 1, /* Four random seeds are calculated with the util_clock_seed() function. */
33 INIT_DEV_RANDOM = 2, /* Random content is read with the function util_fread_dev_random(). */
34 INIT_DEV_URANDOM = 3 /* Random content is read with the function util_fread_dev_urandom(). */
36
37
38typedef enum {
39 MZRAN = 1
41
42
43 typedef unsigned int ( rng_forward_ftype ) ( void * );
44 typedef void ( rng_set_state_ftype ) ( void * , const char * );
45 typedef void ( rng_get_state_ftype ) ( void * , char * );
46 typedef void * ( rng_alloc_ftype ) ( void );
47 typedef void ( rng_free_ftype ) ( void * );
48 typedef void ( rng_fscanf_ftype ) ( void * , FILE * );
49 typedef void ( rng_fprintf_ftype ) ( const void * , FILE * );
50
51 typedef struct rng_struct rng_type;
52
54 void rng_free( rng_type * rng);
55 void rng_free( rng_type * rng);
56 unsigned int rng_forward( rng_type * rng );
57 double rng_get_double( rng_type * rng);
58 void rng_rng_init( rng_type * rng , rng_type * seed_src);
59 void rng_init( rng_type * rng , rng_init_mode init_mode );
61 void rng_fprintf_state( rng_type * rng , FILE * stream );
62 void rng_fscanf_state( rng_type * rng , FILE * stream );
63 int rng_state_size( const rng_type * rng );
64 void rng_save_state( rng_type * rng , const char * filename);
65 void rng_load_state( rng_type * rng , const char * filename);
66
67 void rng_set_state( rng_type * rng , const char * state);
68 void rng_get_state( const rng_type * rng , char * state);
69
70 unsigned int rng_forward( rng_type * rng );
71 double rng_get_double( rng_type * rng );
72 int rng_get_int( rng_type * rng , int max_value );
73 unsigned int rng_get_max_int(const rng_type * rng);
74
75 double rng_std_normal( rng_type * rng );
76 void rng_shuffle_int( rng_type * rng , int * data , size_t num_elements);
77 void rng_shuffle( rng_type * rng , char * data , size_t element_size , size_t num_elements);
78 void rng_free__( void * arg);
79
81
82#ifdef __cplusplus
83}
84#endif
85#endif
static std::string data()
Definition: exprtk.hpp:40022
double rng_std_normal(rng_type *rng)
void *() rng_alloc_ftype(void)
Definition: rng.hpp:46
void() rng_get_state_ftype(void *, char *)
Definition: rng.hpp:45
void rng_free(rng_type *rng)
void rng_get_state(const rng_type *rng, char *state)
void rng_free__(void *arg)
void rng_save_state(rng_type *rng, const char *filename)
void rng_fprintf_state(rng_type *rng, FILE *stream)
rng_alg_type rng_get_type(const rng_type *rng)
unsigned int() rng_forward_ftype(void *)
Definition: rng.hpp:43
void rng_rng_init(rng_type *rng, rng_type *seed_src)
void rng_set_state(rng_type *rng, const char *state)
void rng_fscanf_state(rng_type *rng, FILE *stream)
void() rng_free_ftype(void *)
Definition: rng.hpp:47
void() rng_fprintf_ftype(const void *, FILE *)
Definition: rng.hpp:49
void() rng_set_state_ftype(void *, const char *)
Definition: rng.hpp:44
UTIL_SAFE_CAST_HEADER(rng)
double rng_get_double(rng_type *rng)
unsigned int rng_forward(rng_type *rng)
void rng_shuffle_int(rng_type *rng, int *data, size_t num_elements)
void rng_load_state(rng_type *rng, const char *filename)
void() rng_fscanf_ftype(void *, FILE *)
Definition: rng.hpp:48
struct rng_struct rng_type
Definition: rng.hpp:51
rng_init_mode
Definition: rng.hpp:30
@ INIT_DEV_RANDOM
Definition: rng.hpp:33
@ INIT_CLOCK
Definition: rng.hpp:32
@ INIT_DEFAULT
Definition: rng.hpp:31
@ INIT_DEV_URANDOM
Definition: rng.hpp:34
int rng_state_size(const rng_type *rng)
void rng_shuffle(rng_type *rng, char *data, size_t element_size, size_t num_elements)
void rng_init(rng_type *rng, rng_init_mode init_mode)
rng_alg_type
Definition: rng.hpp:38
@ MZRAN
Definition: rng.hpp:39
unsigned int rng_get_max_int(const rng_type *rng)
int rng_get_int(rng_type *rng, int max_value)
rng_type * rng_alloc(rng_alg_type type, rng_init_mode init_mode)