it kinda work

This commit is contained in:
Milxnor
2023-04-05 07:55:28 -04:00
parent bd4a8da94f
commit 0aa6c49580
25 changed files with 1247 additions and 219 deletions

View File

@@ -0,0 +1,76 @@
#pragma once
#include "inc.h"
struct FRandomStream
{
public:
/**
* Default constructor.
*
* The seed should be set prior to use.
*/
FRandomStream()
: InitialSeed(0)
, Seed(0)
{ }
/**
* Creates and initializes a new random stream from the specified seed value.
*
* @param InSeed The seed value.
*/
FRandomStream(int32 InSeed)
{
Initialize(InSeed);
}
public:
/**
* Initializes this random stream with the specified seed value.
*
* @param InSeed The seed value.
*/
void Initialize(int32 InSeed)
{
InitialSeed = InSeed;
Seed = uint32(InSeed);
}
float GetFraction() const
{
MutateSeed();
float Result;
*(uint32*)&Result = 0x3F800000U | (Seed >> 9);
return Result - 1.0f;
}
FORCEINLINE float FRand() const
{
return GetFraction();
}
protected:
/**
* Mutates the current seed into the next seed.
*/
void MutateSeed() const
{
Seed = (Seed * 196314165U) + 907633515U;
}
private:
// Holds the initial seed.
int32 InitialSeed;
// Holds the current seed. This should be an uint32 so that any shift to obtain top bits
// is a logical shift, rather than an arithmetic shift (which smears down the negative bit).
mutable uint32 Seed;
};