Changeset 28 in Project Repository
 Timestamp:
 09/16/2014 03:30:47 PM (6 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/src/random.ads
r27 r28 13 13 function Maximum(G : in Generator) return Number_Type is abstract; 14 14 15  Return the next random number from the generator. Notice that the generator's state is updated. 15  Return the next random number from the generator. Notice that the generator's state is 16  updated. 16 17 function Next(G : in out Generator) return Number_Type is abstract 17 18 with Post'Class => (0 <= Next'Result and Next'Result <= Maximum(G)); 18 19 19  Returns a random number in the given range (inclusive). Notice that the generator's state is updated. The precondition 20  ensures that every value in the desired range might be returned. Warning! If the maximum of the generator is not an 21  integer multiple of the size of the desired range, the output will be biased. Values in the upper part of the range will 22  not occur frequently enough. 20  Returns a random number in the given range (inclusive). Notice that the generator's state 21  is updated. The precondition ensures that every value in the desired range might be 22  returned. Warning! If the maximum of the generator is not an integer multiple of the size 23  of the desired range, the output will be biased. Values in the upper part of the range 24  will not occur frequently enough. 23 25 function Next(G : in out Generator'Class; Low, High : Number_Type) return Number_Type 24 26 with Pre => (High >= Low) and then (Maximum(G) >= (High  Low + 1)); … … 40 42  41 43 42  This type returns individual bits using a given underlying generator to obtain them. Warning! If the underlying generator 43  has a maximum that is not 2**N  1 for some N, the bits returned here will have bias. This is because the most significant 44  bit of the output of the underlying generator will be set with a probability less than 0.5. 44  This type returns individual bits using a given underlying generator to obtain them. 45  Warning! If the underlying generator has a maximum that is not 2**N  1 for some N, the 46  bits returned here will have bias. This is because the most significant bit of the output 47  of the underlying generator will be set with a probability less than 0.5. 45 48 type Bit_Generator is new Generator with private; 46 49 47  The access parameter on Make allows several Bit_Generators to share the same underlying generator. 50  The access parameter on Make allows several Bit_Generators to share the same underlying 51  generator. 48 52 not overriding function Make(G : access Generator'Class) return Bit_Generator; 49 53 overriding function Maximum(B : in Bit_Generator) return Number_Type … … 56 60  57 61 58  This type returns individual bits using a given underlying generator to obtain them. It returns the least significant bit 59  of each value generated by the underlying generator. This is wasteful of random bits, but it means it is free of the bias 60  problems of Bit_Generator. Warning! Maybe pseudorandom generators do a poor job of randomizing the LSB of their output. 62  This type returns individual bits using a given underlying generator to obtain them. It 63  returns the least significant bit of each value generated by the underlying generator. 64  This is wasteful of random bits, but it means it is free of the bias problems of 65  Bit_Generator. Warning! Maybe pseudorandom generators do a poor job of randomizing the 66  LSB of their output. 61 67 type LSB_Generator is new Generator with private; 62 68 63  The access parameter on Make allows several LSB_Generators to share the same underlying generator. 69  The access parameter on Make allows several LSB_Generators to share the same underlying 70  generator. 64 71 not overriding function Make(G : access Generator'Class) return LSB_Generator; 65 72 overriding function Maximum(B : in LSB_Generator) return Number_Type … … 72 79  73 80 74  This type always has exactly 1_771_875 states. The parameters of the generator are fixed. Warning! Generators of this type75  are unsuitable for security sensitive applications.81  This type always has exactly 1_771_875 states. The parameters of the generator are fixed. 82  Warning! Generators of this type are unsuitable for security sensitive applications. 76 83 type Linear_Congruential is new Seeded_Generator with private; 77 84
Note: See TracChangeset
for help on using the changeset viewer.