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

computing 53-bits random number #55

Open
ng5 opened this issue Jan 19, 2020 · 0 comments
Open

computing 53-bits random number #55

ng5 opened this issue Jan 19, 2020 · 0 comments

Comments

@ng5
Copy link

ng5 commented Jan 19, 2020

I need to be able to send largest possible integer to a web application. This number will be passed back and forth to server.

template <typename T = pcg64_k1024_fast, typename R = int64_t> R computePCG() {
    static thread_local T rng{pcg_extras::seed_seq_from<std::random_device>()};
    return rng();
}

Using above code of PCG, On server I'm able to generate either 32-bit or 64-bit, However Json using 64 bit IEEE 754 - Only provides 53 bits precision for integer. So my options are:

  1. I can use full 64 bit integer, but this will require code change at client application to be able to handle 64 bit change. Would really like to avoid this approach.

OR

  1. Generate 64 bit number using PCG and right shift 11 bits ( To generate 53 bits), Is this safe approach to generate random numbers. Will this number be random enough atleast upto 53 bits.

OR

  1. Is there a better approach to specify number of byes required for random generation. Similar to javascript crypto function:
    https://nodejs.org/api/crypto.html#crypto_crypto_randombytes_size_callback

Thank you for your time and looking into it.

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