/[dtapublic]/projs/trunk/shared_source/c_datd/esrg_rand_int.h
ViewVC logotype

Diff of /projs/trunk/shared_source/c_datd/esrg_rand_int.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 56 by dashley, Sat Oct 29 01:53:01 2016 UTC revision 71 by dashley, Sat Nov 5 11:07:06 2016 UTC
# Line 1  Line 1 
1  //$Header$  //$Header$
2  //-------------------------------------------------------------------------------------------------  //-------------------------------------------------------------------------------------------------
3  //This file is part of "David T. Ashley's Shared Source Code", a set of shared components  //This file is part of "David T. Ashley's Shared Source Code", a set of shared components
4  //integrated into many of David T. Ashley's projects.  //integrated into many of David T. Ashley's projects.
5  //-------------------------------------------------------------------------------------------------  //-------------------------------------------------------------------------------------------------
6  //This source code and any program in which it is compiled/used is provided under the MIT License,  //This source code and any program in which it is compiled/used is provided under the MIT License,
7  //reproduced below.  //reproduced below.
8  //-------------------------------------------------------------------------------------------------  //-------------------------------------------------------------------------------------------------
9  //Permission is hereby granted, free of charge, to any person obtaining a copy of  //Permission is hereby granted, free of charge, to any person obtaining a copy of
10  //this software and associated documentation files(the "Software"), to deal in the  //this software and associated documentation files(the "Software"), to deal in the
11  //Software without restriction, including without limitation the rights to use,  //Software without restriction, including without limitation the rights to use,
12  //copy, modify, merge, publish, distribute, sublicense, and / or sell copies of the  //copy, modify, merge, publish, distribute, sublicense, and / or sell copies of the
13  //Software, and to permit persons to whom the Software is furnished to do so,  //Software, and to permit persons to whom the Software is furnished to do so,
14  //subject to the following conditions :  //subject to the following conditions :
15  //  //
16  //The above copyright notice and this permission notice shall be included in all  //The above copyright notice and this permission notice shall be included in all
17  //copies or substantial portions of the Software.  //copies or substantial portions of the Software.
18  //  //
19  //THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR  //THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20  //IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,  //IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21  //FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE  //FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
22  //AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER  //AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23  //LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,  //LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24  //OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE  //OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25  //SOFTWARE.  //SOFTWARE.
26  //-------------------------------------------------------------------------------------------------  //-------------------------------------------------------------------------------------------------
27  #ifndef ESRG_RAND_INT_H_INCLUDED  #ifndef ESRG_RAND_INT_H_INCLUDED
28     #define ESRG_RAND_INT_H_INCLUDED     #define ESRG_RAND_INT_H_INCLUDED
29    
30     #ifdef MODULE_ESRG_RAND_INT     #ifdef MODULE_ESRG_RAND_INT
31        #define DECMOD_ESRG_RAND_INT        #define DECMOD_ESRG_RAND_INT
32     #else     #else
33        #define DECMOD_ESRG_RAND_INT extern        #define DECMOD_ESRG_RAND_INT extern
34     #endif     #endif
35    
36     //This module is grouped as a collection of algorithms.     //This module is grouped as a collection of algorithms.
37     //At present, there is only one algorithm, but this may     //At present, there is only one algorithm, but this may
38     //change.     //change.
39     //**************************************************************************     //**************************************************************************
40     //**************************************************************************     //**************************************************************************
41     //**********  Algorithm 01:  Power Residue 16807  **************************     //**********  Algorithm 01:  Power Residue 16807  **************************
42     //**************************************************************************     //**************************************************************************
43     //**************************************************************************     //**************************************************************************
44     //This is the state vector.  This is conceptually private, and the     //This is the state vector.  This is conceptually private, and the
45     //caller should not tamper with it or peek into it.     //caller should not tamper with it or peek into it.
46     struct ESRG_RAND_INT_Alg01RngState     struct ESRG_RAND_INT_Alg01RngState
47        {        {
48        unsigned rn_seed_whole;        unsigned rn_seed_whole;
49           //The current whole random number.  This is the random           //The current whole random number.  This is the random
50           //number that will be served up when the first algorithm           //number that will be served up when the first algorithm
51           //is used directly or when a random integer over a large           //is used directly or when a random integer over a large
52           //range is required.           //range is required.
53        unsigned rn_seed_fractional;        unsigned rn_seed_fractional;
54           //The current seed in use for requests for bits or           //The current seed in use for requests for bits or
55           //small portions of bits.           //small portions of bits.
56        unsigned bit_buffer;        unsigned bit_buffer;
57           //A buffer maintained to doll out bits and small random           //A buffer maintained to doll out bits and small random
58           //numbers.  This buffer is emptied from the right.           //numbers.  This buffer is emptied from the right.
59        unsigned n_bb_valid;        unsigned n_bb_valid;
60           //The number of valid bits in the bit buffer.  When there           //The number of valid bits in the bit buffer.  When there
61           //are no more valid bits, the bit buffer must be           //are no more valid bits, the bit buffer must be
62           //restocked.           //restocked.
63        };        };
64        
65     //Initializes the random number generation structure.  If     //Initializes the random number generation structure.  If
66     //(init_val == -1), then the state will be randomized using the system     //(init_val == -1), then the state will be randomized using the system
67     //clock and other system randomness.  This means that the random     //clock and other system randomness.  This means that the random
68     //sequence generated won't be predictable (it will vary from usage     //sequence generated won't be predictable (it will vary from usage
69     //to usage of this module).  If init_val is positive, the positive     //to usage of this module).  If init_val is positive, the positive
70     //value will be used to initialize the state.  The mapping from     //value will be used to initialize the state.  The mapping from
71     //init_val is guaranteed to be deterministic (the same value always     //init_val is guaranteed to be deterministic (the same value always
72     //leads to the same sequences), but uniqueness is not guaranteed:     //leads to the same sequences), but uniqueness is not guaranteed:
73     //different values of init_val may lead to the same sequences.     //different values of init_val may lead to the same sequences.
74     DECMOD_ESRG_RAND_INT     DECMOD_ESRG_RAND_INT
75     void ESRG_RAND_INT_Alg01_Init(struct ESRG_RAND_INT_Alg01RngState *state,     void ESRG_RAND_INT_Alg01_Init(struct ESRG_RAND_INT_Alg01RngState *state,
76                                   int    init_val);                                   int    init_val);
77    
78     //Returns a single random bit.     //Returns a single random bit.
79     DECMOD_ESRG_RAND_INT     DECMOD_ESRG_RAND_INT
80     unsigned int ESRG_RAND_INT_Alg01_RandomBit(     unsigned int ESRG_RAND_INT_Alg01_RandomBit(
81                                   struct ESRG_RAND_INT_Alg01RngState *state                                   struct ESRG_RAND_INT_Alg01RngState *state
82                                   );                                   );
83     //Returns a single random byte.     //Returns a single random byte.
84     DECMOD_ESRG_RAND_INT     DECMOD_ESRG_RAND_INT
85     unsigned int ESRG_RAND_INT_Alg01_RandomByte(     unsigned int ESRG_RAND_INT_Alg01_RandomByte(
86                                   struct ESRG_RAND_INT_Alg01RngState *state                                   struct ESRG_RAND_INT_Alg01RngState *state
87                                   );                                   );
88    
89     DECMOD_ESRG_RAND_INT const char *ESRG_RAND_INT_cvcinfo(void);     DECMOD_ESRG_RAND_INT const char *ESRG_RAND_INT_cvcinfo(void);
90     DECMOD_ESRG_RAND_INT const char *ESRG_RAND_INT_hvcinfo(void);     DECMOD_ESRG_RAND_INT const char *ESRG_RAND_INT_hvcinfo(void);
91     #define ESRG_RAND_INT_H_VERSION ("$Header$")     #define ESRG_RAND_INT_H_VERSION ("$Header$")
92  #endif  #endif
93    
94  //End of esrg_rand_int.h.  //End of esrg_rand_int.h.

Legend:
Removed from v.56  
changed lines
  Added in v.71

dashley@gmail.com
ViewVC Help
Powered by ViewVC 1.1.25