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

[feature] random.unpredictableSeed, from pid, threadid, time #8588

Closed
1 task
timotheecour opened this issue Aug 9, 2018 · 1 comment
Closed
1 task

[feature] random.unpredictableSeed, from pid, threadid, time #8588

timotheecour opened this issue Aug 9, 2018 · 1 comment

Comments

@timotheecour
Copy link
Member

timotheecour commented Aug 9, 2018

same as https://dlang.org/library/std/random/unpredictable_seed.html

EDIT
just figured that nim has this:

proc randomize*() {.benign.} =
    let now = times.getTime()
    randomize(convert(Seconds, Nanoseconds, now.toUnix) + now.nanosecond)

this could be improved for more randomness, as done here: https://github.com/dlang/phobos/blob/v2.081.1/std/random.d#L1549
which mixes pid, threadid, and time

if (!seeded)
        {
            uint threadID = cast(uint) cast(void*) Thread.getThis();
            rand.seed((getpid() + threadID) ^ cast(uint) MonoTime.currTime.ticks);
            seeded = true;
        }
        rand.popFront();
        return cast(uint) (MonoTime.currTime.ticks ^ rand.front);

minor

  • would be good to update docs because randomize doesn't appear next to randomize(seed), and its docstring doesn't contain seed, so its easy to miss.
@timotheecour timotheecour changed the title [feature] random. unpredictableSeed [feature] random.unpredictableSeed Aug 9, 2018
@timotheecour timotheecour changed the title [feature] random.unpredictableSeed [feature] random.unpredictableSeed, from pid, threadid, time Aug 10, 2018
@narimiran
Copy link
Member

I don't see any significant benefit of "more randomness". Closing as rejected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants