hedgewars/uRandom.pas
changeset 5123 b0b57f247e02
parent 4976 088d40d8aba2
child 6580 6155187bf599
equal deleted inserted replaced
5122:9b0513507ba8 5123:b0b57f247e02
    17  *)
    17  *)
    18 
    18 
    19 {$INCLUDE "options.inc"}
    19 {$INCLUDE "options.inc"}
    20 
    20 
    21 unit uRandom;
    21 unit uRandom;
       
    22 (*
       
    23  * This unit supplies platform-independent functions for getting various
       
    24  * pseudo-random values based on a shared seed.
       
    25  *
       
    26  * This is necessary for accomplishing pseudo-random behavior in the game
       
    27  * without causing a desynchronisation of different clients when playing over
       
    28  * a network.
       
    29  *)
    22 interface
    30 interface
    23 uses uFloat;
    31 uses uFloat;
    24 {$INCLUDE "config.inc"}
    32 {$INCLUDE "config.inc"}
    25 
    33 
    26 procedure initModule;
    34 procedure initModule;
    27 procedure freeModule;
    35 procedure freeModule;
    28 
    36 
    29 procedure SetRandomSeed(Seed: shortstring);
    37 procedure SetRandomSeed(Seed: shortstring); // Sets the seed that should be used for generating pseudo-random values.
    30 function  GetRandom: hwFloat; overload;
    38 function  GetRandom: hwFloat; overload; // Returns a pseudo-random hwFloat.
    31 function  GetRandom(m: LongWord): LongWord; overload;
    39 function  GetRandom(m: LongWord): LongWord; overload; // Returns a positive pseudo-random integer smaller than m.
    32 function  rndSign(num: hwFloat): hwFloat;
    40 function  rndSign(num: hwFloat): hwFloat; // Returns num with a random chance of having a inverted sign.
    33 
    41 
    34 implementation
    42 implementation
    35 
    43 
    36 var cirbuf: array[0..63] of Longword;
    44 var cirbuf: array[0..63] of Longword;
    37     n: byte;
    45     n: byte;