Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Random generator is not proper-random, I offer an improvement. #3

Open
sabiland opened this issue Sep 10, 2024 · 0 comments
Open

Random generator is not proper-random, I offer an improvement. #3

sabiland opened this issue Sep 10, 2024 · 0 comments

Comments

@sabiland
Copy link

Loki random generator is not proper-random, if you put in seed gid.x/gid.y. Try to make random noise image with default Loki implementation and you'll see it is not random.

Here is an improved version, which returns proper [0, 1] random numbers.

// seed2 == gid
thread float MetalHelper::random01(const unsigned seed, float2 seed2) {
    Loki l = Loki(seed);
    // IMPROVEMENT here
    float r = fract(sin(dot(float2(seed2.x, seed2.y), float2(12.9898,78.233))) * ((seed2.x + seed2.y) * l.rand()));
    return r;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant