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

Regarding your Seed() function #1

Closed
lordmulder opened this issue Sep 8, 2017 · 1 comment
Closed

Regarding your Seed() function #1

lordmulder opened this issue Sep 8, 2017 · 1 comment

Comments

@lordmulder
Copy link

lordmulder commented Sep 8, 2017

Hello,

regarding your seeding function:

func (w *weyl) Seed(seed int64) {
    *w = weyl{s: (uint64(seed) + 0xb5ad4eceda1ce2a9) | 1}
}

Considering that seed values will often not use the full 64-Bit – which probably means that more often than not the "highest" bits will be zero-padding and the entropy is in the "lowest" bits:

Wouldn't it make sense to left-shift the seed value by one bit-position, rather than OR-ing it with 1?

func (w *weyl) Seed(seed int64) {
    *w = weyl{s: (uint64(seed) << 1) + 0xb5ad4eceda1ce2a9}
}

Note: Still guarantees that the result is odd (as the shifted value is always even and it will be added to an odd number), but rather than discarding the least-significant bit, we discard the most-significant one.

Regards,
MuldeR

@tidwall
Copy link
Owner

tidwall commented Sep 8, 2017

Hi @lordmulder,

Yes, I like this approach very much.

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

2 participants