flare-slang/shader/rng.slang

44 lines
653 B
Plaintext
Raw Normal View History

2025-01-04 16:51:07 -05:00
module rng;
public interface IRngCore
{
[mutating]
public uint64_t next();
[mutating]
public float next_float();
}
uint64_t rotl(uint64_t x, int k)
{
return (x << k) | (x >> (64 - k));
}
float u64_to_float(uint64_t x)
{
return 0;
}
public struct Xoroshiro128Plus : IRngCore
{
internal uint64_t s0;
internal uint64_t s1;
[mutating]
public uint64_t next()
{
var result = s0 + s1;
s1 ^= s0;
s0 = rotl(s0, 24) ^ s1 ^ (s1 << 16);
s1 = rotl(s1, 37);
return result;
}
[mutating]
public float next_float()
{
return u64_to_float(next());
}
}