hedgewars/uRandom.pas
changeset 915 33040b7695c0
parent 527 e23490ce1f06
child 916 1d0022336fbb
equal deleted inserted replaced
914:c2fcafbfc4aa 915:33040b7695c0
    23 {$INCLUDE proto.inc}
    23 {$INCLUDE proto.inc}
    24 
    24 
    25 procedure SetRandomSeed(Seed: shortstring);
    25 procedure SetRandomSeed(Seed: shortstring);
    26 function  GetRandom: hwFloat; overload;
    26 function  GetRandom: hwFloat; overload;
    27 function  GetRandom(m: LongWord): LongWord; overload;
    27 function  GetRandom(m: LongWord): LongWord; overload;
       
    28 function  rndSign(num: hwFloat): hwFloat;
       
    29 {$IFDEF DEBUGFILE}
       
    30 procedure DumpBuffer;
       
    31 {$ENDIF}
    28 
    32 
    29 implementation
    33 implementation
       
    34 {$IFDEF DEBUGFILE}
       
    35 uses uMisc;
       
    36 {$ENDIF}
    30 var cirbuf: array[0..63] of Longword;
    37 var cirbuf: array[0..63] of Longword;
    31     n: byte = 54;
    38     n: byte = 54;
    32 
    39 
    33 function GetNext: Longword;
    40 function GetNext: Longword;
    34 begin
    41 begin
    70 begin
    77 begin
    71 GetNext;
    78 GetNext;
    72 GetRandom:= GetNext mod m
    79 GetRandom:= GetNext mod m
    73 end;
    80 end;
    74 
    81 
       
    82 function rndSign(num: hwFloat): hwFloat;
       
    83 begin
       
    84 num.isNegative:= odd(GetNext);
       
    85 rndSign:= num
       
    86 end;
       
    87 
       
    88 {$IFDEF DEBUGFILE}
       
    89 procedure DumpBuffer;
       
    90 var i: LongInt;
       
    91 begin
       
    92 for i:= 0 to 63 do
       
    93 	AddFileLog('[' + inttostr(i) + '] = ' + inttostr(cirbuf[i]))
       
    94 end;
       
    95 {$ENDIF}
       
    96 
    75 end.
    97 end.