Yasiu Math
1
Collection of mathematic functions that help create game mechanics and procedural tools
Toggle main menu visibility
Loading...
Searching...
No Matches
PCG_RNG.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2026 Grzegorz Krug.
3
* All Rights Reserved.
4
*/
5
7
8
#pragma once
9
10
11
#include "CoreMinimal.h"
12
13
14
#include "Components//ActorComponent.h"
15
16
17
#include "PCG_RNG.generated.h"
18
19
26
UCLASS(BlueprintType, Blueprintable, DefaultToInstanced)
27
class
UPCG_RNG32
: public UObject {
28
GENERATED_BODY()
29
30
31
public
:
32
virtual
void
GetLifetimeReplicatedProps( TArray<class FLifetimeProperty>& OutLifetimeProps )
const override
;
33
38
UFUNCTION(BlueprintCallable, Category=
"Yasiu|RNG"
)
39
void
InitBP
( int64 StateIn, int64 StreamIn );
40
42
UFUNCTION(BlueprintCallable, Category=
"Yasiu|RNG"
)
43
int64
GetState
() const;
44
46
UFUNCTION(BlueprintCallable, Category=
"Yasiu|RNG"
)
47
void
SetState
( int64 stateIn );
48
50
UFUNCTION(BlueprintCallable, Category=
"Yasiu|RNG"
)
51
void
SetNoiseStream
( int64 streamIn );
52
56
UFUNCTION(BlueprintCallable, Category=
"Yasiu|RNG"
)
57
double
GetNextDouble
();
58
60
UFUNCTION(BlueprintCallable, Category=
"Yasiu|RNG"
)
61
double
GetCurrentDouble
() const;
62
64
UFUNCTION(BlueprintCallable, Category=
"Yasiu|RNG"
)
65
int
GetNextInt
(
int
A,
int
B );
66
68
UFUNCTION(BlueprintCallable, Category=
"Yasiu|RNG"
)
69
int
GetCurrentInt
(
int
A,
int
B ) const;
70
71
72
protected:
73
virtual uint32 CurrentNumber() const;
74
75
uint32 NextNumber();
76
77
UPROPERTY(Replicated, SaveGame)
78
uint64 state = 0x853c49e6748fea9bULL;
79
81
UPROPERTY(Replicated, SaveGame)
82
uint64
stream
= 0xda3e39cb94b95bdbULL;
// must be odd
83
};
84
85
91
UCLASS(BlueprintType, Blueprintable, meta=(BlueprintSpawnableComponent), DefaultToInstanced)
92
class YASIUMATH_API UPCG32_RNGComponent : public UActorComponent {
93
GENERATED_BODY()
94
95
96
public
:
97
UPCG32_RNGComponent();
98
99
virtual
void
GetLifetimeReplicatedProps( TArray<class FLifetimeProperty>& OutLifetimeProps )
const override
;
100
101
UPROPERTY(BlueprintReadWrite, Replicated, Category=
"Yasiu|RNG"
)
102
TObjectPtr<UPCG_RNG32> RNG;
103
104
UFUNCTION(BlueprintCallable, Category=
"Yasiu|RNG"
)
105
void
InitBP( int64 State, int64 Noise );
106
107
UFUNCTION(BlueprintCallable, Category=
"Yasiu|RNG"
)
108
int64 GetState()
const
;
109
110
UFUNCTION(BlueprintCallable, Category=
"Yasiu|RNG"
)
111
void
SetState( int64 State );
112
113
UFUNCTION(BlueprintCallable, Category=
"Yasiu|RNG"
)
114
void
SetStreamNoise( int64 Noise );
115
116
UFUNCTION(BlueprintCallable, Category=
"Yasiu|RNG"
, BlueprintPure=
false
)
117
int
GetCurrentInt(
int
min,
int
max )
const
;
118
119
UFUNCTION(BlueprintCallable, Category=
"Yasiu|RNG"
)
120
int
GetNextInt(
int
min,
int
max );
121
122
UFUNCTION(BlueprintCallable, Category=
"Yasiu|RNG"
, BlueprintPure=
false
)
123
double
GetCurrentDouble()
const
;
124
125
UFUNCTION(BlueprintCallable, Category=
"Yasiu|RNG"
)
126
double
GetNextDouble();
127
};
UPCG_RNG32
State based RNG, good for MonteCarlo sampling.
Definition
PCG_RNG.h:27
UPCG_RNG32::SetNoiseStream
void SetNoiseStream(int64 streamIn)
Set stream variable, used for generating next states. (must bee odd or will be changed to odd).
UPCG_RNG32::SetState
void SetState(int64 stateIn)
Set only state in PCG.
UPCG_RNG32::stream
uint64 stream
Noise for generation numbers.
Definition
PCG_RNG.h:82
UPCG_RNG32::GetNextDouble
double GetNextDouble()
Generate next random number.
UPCG_RNG32::InitBP
void InitBP(int64 StateIn, int64 StreamIn)
Initial set with 2 variables.
UPCG_RNG32::GetCurrentInt
int GetCurrentInt(int A, int B) const
Get random value in range <A, B>.
UPCG_RNG32::GetState
int64 GetState() const
Get current state in PCG.
UPCG_RNG32::GetNextInt
int GetNextInt(int A, int B)
Get random value in range <A, B>.
UPCG_RNG32::GetCurrentDouble
double GetCurrentDouble() const
Return last random double in range <0, 1>.
Source
YasiuMath
Public
PCG_RNG.h
Generated by
1.17.0