Yasiu Math 1
Collection of mathematic functions that help create game mechanics and procedural tools
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
26UCLASS(BlueprintType, Blueprintable, DefaultToInstanced)
27class UPCG_RNG32 : public UObject {
28 GENERATED_BODY()
29
30
31public:
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
72protected:
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
91UCLASS(BlueprintType, Blueprintable, meta=(BlueprintSpawnableComponent), DefaultToInstanced)
92class YASIUMATH_API UPCG32_RNGComponent : public UActorComponent {
93 GENERATED_BODY()
94
95
96public:
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};
State based RNG, good for MonteCarlo sampling.
Definition PCG_RNG.h:27
void SetNoiseStream(int64 streamIn)
Set stream variable, used for generating next states. (must bee odd or will be changed to odd).
void SetState(int64 stateIn)
Set only state in PCG.
uint64 stream
Noise for generation numbers.
Definition PCG_RNG.h:82
double GetNextDouble()
Generate next random number.
void InitBP(int64 StateIn, int64 StreamIn)
Initial set with 2 variables.
int GetCurrentInt(int A, int B) const
Get random value in range <A, B>.
int64 GetState() const
Get current state in PCG.
int GetNextInt(int A, int B)
Get random value in range <A, B>.
double GetCurrentDouble() const
Return last random double in range <0, 1>.