hedgewars/uRandom.pas
branchwebgl
changeset 9168 20ff80421736
parent 9127 e350500c4edb
child 10015 4feced261c68
equal deleted inserted replaced
9166:3774ac58e65e 9168:20ff80421736
    29  *)
    29  *)
    30 interface
    30 interface
    31 uses uFloat;
    31 uses uFloat;
    32 
    32 
    33 procedure SetRandomSeed(Seed: shortstring; dropAdditionalPart: boolean); // Sets the seed that should be used for generating pseudo-random values.
    33 procedure SetRandomSeed(Seed: shortstring; dropAdditionalPart: boolean); // Sets the seed that should be used for generating pseudo-random values.
    34 function  GetRandomf: hwFloat; overload; // Returns a pseudo-random hwFloat.
    34 function  GetRandomf: hwFloat; // Returns a pseudo-random hwFloat.
    35 function  GetRandom(m: LongWord): LongWord; overload; inline; // Returns a positive pseudo-random integer smaller than m.
    35 function  GetRandom(m: LongWord): LongWord; inline; // Returns a positive pseudo-random integer smaller than m.
    36 procedure AddRandomness(r: LongWord); inline;
    36 procedure AddRandomness(r: LongWord); inline;
    37 function  rndSign(num: hwFloat): hwFloat; // Returns num with a random chance of having a inverted sign.
    37 function  rndSign(num: hwFloat): hwFloat; // Returns num with a random chance of having a inverted sign.
    38 
    38 
    39 
    39 
    40 implementation
    40 implementation
    90 GetNext;
    90 GetNext;
    91 GetRandomf.isNegative:= false;
    91 GetRandomf.isNegative:= false;
    92 GetRandomf.QWordValue:= GetNext
    92 GetRandomf.QWordValue:= GetNext
    93 end;
    93 end;
    94 
    94 
    95 function GetRandom(m: LongWord): LongWord; overload; inline;
    95 function GetRandom(m: LongWord): LongWord; inline;
    96 begin
    96 begin
    97 GetNext;
    97 GetNext;
    98 GetRandom:= GetNext mod m
    98 GetRandom:= GetNext mod m
    99 end;
    99 end;
   100 
   100