Yasiu Math 1
Collection of mathematic functions that help create game mechanics and procedural tools
Loading...
Searching...
No Matches
SquirrelRNG.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 "SquirrelRNG.generated.h"
12
13
17UCLASS(BlueprintType, Blueprintable)
18class YASIUMATH_API USquirrel13_RNG : public UObject {
19public:
20 GENERATED_BODY()
21
22 USquirrel13_RNG() {};
23
24 USquirrel13_RNG( unsigned int seed )
25 : m_seed(seed), init_seed(seed) {};
26
27 USquirrel13_RNG( int position, unsigned int seed )
28 : m_position(position), m_seed(seed), init_position(position), init_seed(seed) {};
29
30 USquirrel13_RNG( int position, unsigned int seed, unsigned int variant )
31 : m_position(position), m_seed(seed), m_variant(variant), init_position(position), init_seed(seed) {};
32
33protected:
34 UPROPERTY()
35 int m_position{0};
36
37 UPROPERTY()
38 unsigned int m_seed{1};
39
41 UPROPERTY()
42 int m_variant{0};
43
44 UPROPERTY()
45 unsigned int init_position = 0;
46
47 // UPROPERTY(BlueprintReadWrite)
48 int32 init_seed = 0;
49
50public:
55 UFUNCTION(BlueprintCallable, Category="RNG")
56 void InitBP( int seed, int position = 0 );
57
59 uint32_t get_current_random() const;
60
62 uint32_t get_next_random();
63
65 UFUNCTION(BlueprintCallable, Category="RNG")
66 int GetNextInt( int min, int max );
67
69 UFUNCTION(BlueprintCallable, Category="RNG")
70 int GetCurrentInt( int min, int max ) const;
71
75 UFUNCTION(BlueprintCallable, Category="RNG")
76 double GetNextDouble();
77
79 UFUNCTION(BlueprintCallable, Category="RNG")
80 double GetCurrentDouble() const;
81
83 UFUNCTION(BlueprintCallable, Category="RNG")
84 void SetPosition( int new_position );
85
90 UFUNCTION(BlueprintCallable, Category="RNG")
91 void OffsetPosition( int offset = 1 );
92
94 UFUNCTION(BlueprintCallable, Category="RNG")
95 void SetSeed( int new_seed );
96
100 UFUNCTION(BlueprintCallable, Category="RNG")
101 void SetNoiseVariant( int newVariant = 0 );
102
104 UFUNCTION(BlueprintCallable, Category="RNG")
106
108 static uint32_t RNG_0( int position, unsigned int seed );
109
111 static uint32_t RNG_1( int position, unsigned int seed );
112
114 static uint32_t RNG_2( int position, unsigned int seed );
115
117 static uint32_t RNG_3( int position, unsigned int seed );
118
120 static uint32_t RNG_4( int position, unsigned int seed );
121
123 static uint32_t RNG_5( int position, unsigned int seed );
124
126 virtual void Serialize( FArchive& Ar ) override;
127};
void ResetSeedPos()
Reset to internal initial values.
void SetNoiseVariant(int newVariant=0)
Internal noise variants (it is not initialized), default=0, max=5 Invalid variants will use default n...
double GetCurrentDouble() const
Return last random double in range <0, 1>.
static uint32_t RNG_3(int position, unsigned int seed)
Noise variant.
static uint32_t RNG_0(int position, unsigned int seed)
Noise variant.
static uint32_t RNG_5(int position, unsigned int seed)
Noise variant.
void OffsetPosition(int offset=1)
Offset current position, can be positive and negative.
void SetSeed(int new_seed)
Set seed noise seed.
int m_variant
variable related to selected noise variant
Definition SquirrelRNG.h:42
static uint32_t RNG_1(int position, unsigned int seed)
Noise variant.
static uint32_t RNG_4(int position, unsigned int seed)
Noise variant.
static uint32_t RNG_2(int position, unsigned int seed)
Noise variant.
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 InitBP(int seed, int position=0)
Modify internal values to custom.
virtual void Serialize(FArchive &Ar) override
Serialization of RNG Object.