Navigation
API > API/Runtime > API/Runtime/CoreUObject
A RefCounted RandomStream and a threadlocal global accessor for accessing a currently scoped instance. Intended use is for cook operations to set a scope that can be used for deterministic replacement of random or other fundamentally non-deterministic calculations such as NewGuid.
Like RandomStream, const functions on FCookRand can have the side effect of mutating the RandomSeed to the next random value.
An FCookRand instance is not thread-safe because call order in a threaded environment is in general non-deterministic. Callers that run multithreaded operations using FCookRand should maintain their own FCookRand and should pass exclusive ownership of it to each task thread in a deterministic order.
Example usage:
void HighLevelFunctionWithUserCode() { int32 MySeed = ComputeMyDeterministicSeed(); UE::Cook::FCookRandScope Scope(MySeed, UE::Cook::ECookRandScope::Overwrite);
// ... Call UserCode that uses MyAPI }
FGuid MyAPI::NewGuid() { TRefCountPtr
| Name | FCookRand |
| Type | class |
| Header File | /Engine/Source/Runtime/CoreUObject/Public/Cooker/CookRand.h |
| Include Path | #include "Cooker/CookRand.h" |
Syntax
class FCookRand : public FRefCountedObject
Inheritance Hierarchy
- TAtomicRefCount → FRefCountedObject → FCookRand
Constructors
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
FCookRand
(
int32 InSeed |
Cooker/CookRand.h |
Variables
Protected
| Name | Type | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|---|
| RandomStreamVar | FRandomStream | Cooker/CookRand.h |
Functions
Public
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
FGuid RandomGuid() |
Cooker/CookRand.h | ||
const FRandomStream & RandomStream() |
Inline implementations. | Cooker/CookRand.h |
Static
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
static int32 ConstructSeed
(
FStringView String |
Construct a seed to initialize a CookRand, from a StringView. Normalizes to UTF8 and LowerCase. | Cooker/CookRand.h | |
static TRefCountPtr< FCookRand > GetThreadScope() |
Get the FCookRand that was declared in a containing scope on the current thread, or null if none has been declared. | Cooker/CookRand.h |