Yasiu Math 1
Collection of mathematic functions that help create game mechanics and procedural tools
Loading...
Searching...
No Matches
SquirrelRNG.h
1/*
2 * Copyright (c) 2025 Grzegorz Krug.
3 * All Rights Reserved.
4 */
5
6#pragma once
7#include "CoreMinimal.h"
8
9#include "SquirrelRNG.generated.h"
10
11
15UCLASS(BlueprintType)
16class YASIUMATH_API USquirrel13_RNG : public UObject {
17public:
18 GENERATED_BODY()
19
20 USquirrel13_RNG() {};
21
22 USquirrel13_RNG( unsigned int seed )
23 : m_seed(seed), init_seed(seed) {};
24
25 USquirrel13_RNG( int position, unsigned int seed )
26 : m_position(position), m_seed(seed), init_position(position), init_seed(seed) {};
27
28 USquirrel13_RNG( int position, unsigned int seed, unsigned int variant )
29 : m_position(position), m_seed(seed), m_variant(variant), init_position(position), init_seed(seed) {};
30
31protected:
32 UPROPERTY()
33 int m_position{0};
34
35 UPROPERTY()
36 unsigned int m_seed{1};
37
38 UPROPERTY()
39 int m_variant{0};
40
41 UPROPERTY()
42 unsigned int init_position = 0;
43
44 // UPROPERTY(BlueprintReadWrite)
45 int32 init_seed = 0;
46
47public:
52 UFUNCTION(BlueprintCallable, Category="RNG")
53 void InitBP( int seed, int position = 0 );
54
56 uint32_t get_current_random() const;
57
59 uint32_t get_random();
60
62 UFUNCTION(BlueprintCallable, Category="RNG")
63 int GetNextInt( int min, int max );
64
66 UFUNCTION(BlueprintCallable, Category="RNG")
67 int GetCurrentInt( int min, int max ) const;
68
72 UFUNCTION(BlueprintCallable, Category="RNG")
73 double GetNextDouble();
74
76 UFUNCTION(BlueprintCallable, Category="RNG")
77 double GetCurrentDouble() const;
78
80 UFUNCTION(BlueprintCallable, Category="RNG")
81 void SetPosition( int new_position );
82
84 UFUNCTION(BlueprintCallable, Category="RNG")
85 void IncrementPosition( int offset=1 );
86
88 UFUNCTION(BlueprintCallable, Category="RNG")
89 void SetSeed( int new_seed );
90
92 UFUNCTION(BlueprintCallable, Category="RNG")
93 void SetNoiseVariant( int newVariant=0 );
94
96 UFUNCTION(BlueprintCallable, Category="RNG")
98
99 static uint32_t RNG_0( int position, unsigned int seed );
100
101 static uint32_t RNG_1( int position, unsigned int seed );
102
103 static uint32_t RNG_2( int position, unsigned int seed );
104
105 static uint32_t RNG_3( int position, unsigned int seed );
106
108 virtual void Serialize( FArchive& Ar ) override;
109};
void ResetSeedPos()
Reset to internal initial values.
void SetNoiseVariant(int newVariant=0)
Internal noise variants (it is not initialized), default=0, max=3.
double GetCurrentDouble() const
Return last random double in range <0, 1>.
void SetSeed(int new_seed)
Set seed noise seed.
double GetNextDouble()
Move position by 1 and return double in range <0, 1>.
int GetNextInt(int min, int max)
Move position by 1 and return random value as integer in range <min, max>.
int GetCurrentInt(int min, int max) const
Return random value scaled to integer range <min, max> at current position.
void SetPosition(int new_position)
Set generator position.
void IncrementPosition(int offset=1)
Offset generator position.
void InitBP(int seed, int position=0)
Modify internal values to custom.
virtual void Serialize(FArchive &Ar) override
Serialization of RNG Object.