Page MenuHomeFeedback Tracker

Fix RandomGenerator::RandInt limitations and failure behavior
Assigned, NormalPublic

Description

RandInt and RandIntInclusive on the RandomGenerator class seem to have limits according to one dev peeking at it for me. Only values up to 0x7fff are possible. If you go beyond that instead of an error in the retail version you get only values that are either the min param or 16 bit max value 65535. Nothing in between is returned anymore.

I want to be able to get "random" ints from the full integer range 0 to int.MAX without any workarounds.

RandomGenerator rand();
rand.SetSeed(System.GetUnixTime());
for(int i = 0; i < 10; i++)
{
    int randInt = rand.RandInt(0, int.MAX);
    Print(randInt);
}

SCRIPT : int randInt = 0
SCRIPT : int randInt = 65535
SCRIPT : int randInt = 0
SCRIPT : int randInt = 0
SCRIPT : int randInt = 0
SCRIPT : int randInt = 65535
SCRIPT : int randInt = 65535
SCRIPT : int randInt = 65535
SCRIPT : int randInt = 65535
SCRIPT : int randInt = 0

This limitation seems very arbitrary. Especially given how changing it to use float and then cast works:

int randInt = (int)rand.RandFloatXY(0, int.MAX);

SCRIPT : int randInt = 2014048256
SCRIPT : int randInt = 2098133504
SCRIPT : int randInt = 17760798
...

Details

Severity
Major
Resolution
Open
Reproducibility
Always
Operating System
Windows 10 x64
Category
General

Event Timeline

Geez changed the task status from New to Assigned.May 19 2023, 12:46 PM