GithubHelp home page GithubHelp logo

Comments (4)

guilload avatar guilload commented on July 19, 2024

Hi Mike,

I haven't uploaded the package to PyPI (the Python Package Index) yet. I'm waiting for more feedback and reviews to do so. Can you take a look at the seed function in pyisaac.c and check If I have properly initialised the generator? Do I need to add an additional call to the isaac function, as suggested by your comments on reddit?

If you really want to install the package, clone the repository, cd into the pyisaac directory and run python setup.py build_ext --inplace. Then, in the very same directory, you can launch python and import pyisaac.

Thank you for your time!

from pyisaac.

BonzaiThePenguin avatar BonzaiThePenguin commented on July 19, 2024

The recommended way of seeding ISAAC is to write the seed value over and over until it fills the internal arrays, rather than initializing with zeroes and writing the seed value once; and calling isaac() twice is a way to work around a potential security flaw someone discovered with some of the starting states. Basically if you don't call it twice there are some seed values that are within the realm of possibility of brute-forcing to recover the seed, which would break the cryptographic security.

from pyisaac.

BonzaiThePenguin avatar BonzaiThePenguin commented on July 19, 2024

By the way, here's an interface for the RNG you may find useful:

#define return_random(type) \
   me->randcnt -= sizeof(type); \
   if (me->randcnt < 0) { isaac(me); me->randcnt = 256 * sizeof(me->randrsl[0]) - sizeof(type); } \
   return *((type *)((uint8 *)me->randrsl)[me->randcnt]); \

int8_t random_int8(randctx *me) { return_random(int8_t); }
int16_t random_int16(randctx *me) { return_random(int16_t); }
int32_t random_int32(randctx *me) { return_random(int32_t); }
int64_t random_int64(randctx *me) { return_random(int64_t); }
uint8_t random_uint8(randctx *me) { return_random(uint8_t); }
uint16_t random_uint16(randctx *me) { return_random(uint16_t); }
uint32_t random_uint32(randctx *me) { return_random(uint32_t); }
uint64_t random_uint64(randctx *me) { return_random(uint64_t); }

bool random_bool(randctx *me) { return (random_uint8(me) > 0x7F); }
float random_float(randctx *me) { return (random_uint32(me) % 0xFFFFFF80)/(float)0x100000000; } // 0xFFFFFF7F is the largest value that returns < 1.0 for this division
double random_double(randctx *me) { return random_uint64(me)/(double)1.84467440737096e19; } // even 0xFFFFFFFFFFFFFFFF returns a value < 1.0

(randcnt is initialized to 256 * sizeof(me->rsl[0]) at the end of set_seed, after calling isaac() once or twice)

It isn't perfect (if there are three bytes of random bits remaining in the randrsl array and you request a uint32, it calls isaac and reads four bytes from the new set of data, rather than using those three bytes and only needing one more), but the logic for the random floats and doubles was tested carefully and that's usually hard to get right.

from pyisaac.

guilload avatar guilload commented on July 19, 2024

Great stuff! Thank you. I will commit within the week.

from pyisaac.

Related Issues (1)

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.