mirror of
https://github.com/1dot13/source.git
synced 2026-08-19 14:20:30 +02:00
New option NEW_RANDOM (default TRUE) enables new code for random number generation.
Fixed PreRandom(1) bug in AddPlacementToWorld. AddPossiblePendingEnemiesToBattle: use Random(4) instead of GetRndNum(3) for random insertion code. git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@8747 3b4a5df2-a311-0410-b5c6-a8a6f20db521
This commit is contained in:
@@ -40,6 +40,27 @@ UINT32 MPPreRandom( UINT32 uiRange )
|
||||
UINT32 guiPreRandomIndex;
|
||||
UINT32 guiPreRandomNums[MAX_PREGENERATED_NUMS];
|
||||
|
||||
#include <random>
|
||||
|
||||
std::random_device gRandomDevice; // only used once to initialize (seed) engine
|
||||
std::mt19937 gRandomNumberGenerator(gRandomDevice()); // random-number engine used (Mersenne-Twister in this case)
|
||||
|
||||
UINT32 NewRandom(UINT32 max)
|
||||
{
|
||||
if (is_networked && is_client)
|
||||
return MPPreRandom(max);
|
||||
|
||||
if (max <= 1)
|
||||
return 0;
|
||||
|
||||
UINT32 min = 0;
|
||||
|
||||
std::uniform_int_distribution<int> uni(min, max - 1); // guaranteed unbiased
|
||||
|
||||
auto random_integer = uni(gRandomNumberGenerator);
|
||||
return random_integer;
|
||||
}
|
||||
|
||||
UINT32 GetRndNum(UINT32 maxnum)
|
||||
{
|
||||
if (is_networked && is_client)
|
||||
@@ -52,8 +73,6 @@ UINT32 GetRndNum(UINT32 maxnum)
|
||||
{
|
||||
GetCursorPos(&pt);// Get cursor location
|
||||
srand(maxnum ^ rnd ^ pt.x ^ pt.y ^ GetTickCount());
|
||||
//SendFmtMsg("Random Number Generator Reinitialized.");
|
||||
//for(int l=0;l<100;l++)SendFmtMsg("%2d", Random(100));
|
||||
}
|
||||
if(maxnum == 0)
|
||||
return(0);
|
||||
|
||||
Reference in New Issue
Block a user