FRandomStream

Implements a thread-safe SRand based RNG.

Windows
MacOS
Linux

Syntax

struct FRandomStream

Remarks

Implements a thread-safe SRand based RNG.

Very bad quality in the lower bits. Don't use the modulus (%) operator.

Constructors

Name Description

Public function

FRandomStream()

Default constructor.

The seed should be set prior to use.

Public function

FRandomStream

(
    int32 InSeed
)

Creates and initializes a new random stream from the specified seed value.

Functions

Name Description

Public function Const

bool

 

ExportTextItem

(
    FString& ValueStr,
    FRandomStream const& DefaultValue,
    UObject* Parent,
    int32 PortFlags,
    UObject* ExportRootScope
)

Exports the RandomStreams value to a string.

Public function Const

float

 

FRand()

Mirrors the random number API in FMath

Public function Const

float

 

FRandRange

(
    float InMin,
    float InMax
)

Helper function for rand implementations.

Public function

void

 

GenerateNewSeed()

Generates a new random seed.

Public function Const

int32

 

GetCurrentSeed()

Gets the current seed.

Public function Const

float

 

GetFraction()

Returns a random number between 0 and 1.

Public function Const

int32

 

GetInitialSeed()

Public function Const

FVector

 

GetUnitVector()

Returns a random vector of unit size.

Public function Const

uint32

 

GetUnsignedInt()

Returns a random number between 0 and MAXUINT.

Public function

void

 

Initialize

(
    int32 InSeed
)

Initializes this random stream with the specified seed value.

Protected function Const

void

 

MutateSeed()

Mutates the current seed into the next seed.

Public function Const

int32

 

RandHelper

(
    int32 A
)

Helper function for rand implementations.

Public function Const

int32

 

RandRange

(
    int32 Min,
    int32 Max
)

Helper function for rand implementations.

Public function Const

void

 

Reset()

Resets this random stream to the initial seed value.

Public function Const

FVector

 

VRand()

Returns a random vector of unit size.

Public function Const

FVector

 

VRandCone

(
    FVector const& Dir,
    float ConeHalfAngleRad
)

Returns a random unit vector, uniformly distributed, within the specified cone.

Public function Const

FVector

 

VRandCone

(
    FVector const& Dir,
    float HorizontalConeHalfAngleRad,
    float VerticalConeHalfAngleRad
)

Returns a random unit vector, uniformly distributed, within the specified cone.

References

Module

Core

Header

Runtime/Core/Public/Math/RandomStream.h

Welcome to the new Unreal Engine 4 Documentation site!

We're working on lots of new features including a feedback system so you can tell us how we are doing. It's not quite ready for use in the wild yet, so head over to the Documentation Feedback forum to tell us about this page or call out any issues you are encountering in the meantime.

We'll be sure to let you know when the new system is up and running.

Post Feedback