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) 2025 Grzegorz Krug.
3 * All Rights Reserved.
4 */
6
7#pragma once
8
9#include "CoreMinimal.h"
10
11#include "PCG_RNG.generated.h"
12
13
17UCLASS(BlueprintType, Blueprintable)
18class UPCG32_RNG : public UObject {
19 GENERATED_BODY()
20
21public:
22 uint32_t next();
23
24 UFUNCTION(BlueprintCallable, Category="RNG")
25 void InitBP( int64 stateIn, int64 streamIn );
26
27 UFUNCTION(BlueprintCallable, Category="RNG")
28 void SetState( int64 stateIn ) { state = static_cast<uint64_t>(stateIn); };
29
31 UFUNCTION(BlueprintCallable, Category="RNG")
32 void SetStream( int64 streamIn ) { stream = static_cast<uint64_t>(streamIn); };
33
37 UFUNCTION(BlueprintCallable, Category="RNG")
38 double GetNextDouble();
39
41 UFUNCTION(BlueprintCallable, Category="RNG")
42 double GetCurrentDouble() const;
43
45 UFUNCTION(BlueprintCallable, Category="RNG")
46 int GetNextInt( int A, int B );
47
49 UFUNCTION(BlueprintCallable, Category="RNG")
50 int GetCurrentInt( int A, int B ) const;
51
53 virtual void Serialize( FArchive& Ar ) override;
54
55protected:
56 uint64_t state = 0x853c49e6748fea9bULL;
57 uint64_t stream = 0xda3e39cb94b95bdbULL; // must be odd
58 uint32_t last = -1;
59};
State based RNG, good for MonteCarlo.
Definition PCG_RNG.h:18
double GetNextDouble()
Generate next random number.
int GetCurrentInt(int A, int B) const
Get random value in range <A, B>.
void SetStream(int64 streamIn)
Stream used for generating new numbers.
Definition PCG_RNG.h:32
double GetCurrentDouble() const
Return last random double in range <0, 1>.
int GetNextInt(int A, int B)
Get random value in range <A, B>.