Giter Club home page Giter Club logo

Comments (5)

lemire avatar lemire commented on June 18, 2024

Can you elaborate ?

This library is not really about number generation per se, but rather about a faster replacement for random.randint.

Please describe what you are trying to do.

from fastrand.

Hurd8x avatar Hurd8x commented on June 18, 2024

I try to generate binary number's in length from 68 to 120 bits(0 and 1).

random.randint is too slow for me, and not get result.

I compare all generated numbers for ex,thith this 60 bit lenght number:

0b010110010001111011101000010000011101011010111110101010111100

And then I find number, code break.

???

Thank you very mach for your answers !!

from fastrand.

lemire avatar lemire commented on June 18, 2024

So call fastrand.xorshift128plus() & 0x3ffffffffffffff to get a 58-bit random number. For a 59-bit number, do fastrand.xorshift128plus() & 0x7ffffffffffffff. It should be fast:

 $ python3 -m timeit -s 'import random' 'random.randint(0,0x3ffffffffffffff)'
1000000 loops, best of 5: 371 nsec per loop
$ python3 -m timeit -s 'import fastrand' 'fastrand.xorshift128plus() & 0x3ffffffffffffff'
5000000 loops, best of 5: 42 nsec per loop

from fastrand.

lemire avatar lemire commented on June 18, 2024

If you need a 120 bits, call fastrand.xorshift128plus() to get a 64-bit number, then call fastrand.xorshift128plus() & 0xffffffffffffff to get the remaining 56 bits.

from fastrand.

Hurd8x avatar Hurd8x commented on June 18, 2024

Thank you so mach, Mister ))

from fastrand.

Related Issues (16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.