Seeded FMath::Rand

I was looking at the GenericPlatformMap.cpp file, because I need to choose a seeded random int generator.
I found the standard Rand() (int between 0 and RAND_MAX), FRand() (float between 0 and 1) and SRand() (seeded float between 0 and 1).

But is there a reason why there is not a seeded Rand()? Or did I miss some function that acts like a Rand() but with seed?

Thanks in advance

1 Like

Hello,

I’m not sure about your question, but for random I’m using
FMath::FRandRange(From, To)

in your case it should be

FMath::FRandRange(0.0f, 1.0f)

I hope it will help,
D.

It’s not seeded

Hello, I think what you need is FRandomStream

-Orfeas

Didn’t know I could get a rand uint from the randomstream, thanks

You must Initialize the stream like this to have new seed or it will always use seed zero

FRandomStream Stream(FMath::Rand());

than use it to create random stuff

int

Stream.RandRange(0,999)

float

Stream.FRandRange(0.0f,1.0f)

bool with weight

UKismetMathLibrary::RandomBoolWithWeightFromStream(Weight, Stream)

to re generate the seed use

Stream.GenerateNewSeed()
1 Like