Code Monkey home page Code Monkey logo

Comments (6)

alicebob avatar alicebob commented on May 23, 2024

from miniredis.

alicebob avatar alicebob commented on May 23, 2024

Hi @zikaeroh,

I've implemented it in #87. I choose to do this in NewMiniRedis():

    source := rand.NewSource(rand.Int63())
    m := Miniredis{
        ....
        rand:        rand.New(source),
    }

This way seeding the global source still has some effect in Miniredis, while it give the option to override the seed. It's not 100% the same as before, but it's the simplest thing to do.

from miniredis.

zikaeroh avatar zikaeroh commented on May 23, 2024

I'll be happy to look at it more closely later. My first impression (skimming on my phone) that it'd definitely lead to different results between miniredis versions (since you're using a seed from Rand), and might also require some locking, but I haven't tested to see. I had actually been planning on submitting my own PR for consideration (but hadn't had time since asking).

from miniredis.

zikaeroh avatar zikaeroh commented on May 23, 2024

I opened a slightly different PR (#89) for your consideration; this one instead calls the global rand as it would have before, but will switch to an internal version when requested. I think this is better than always using an internal copy with rand.Int63() as a seed because:

  • Using rand.Int63() changes the seed used (as it wouldn't output 1, Go's default seed), so those who had used the old advice of rand.Seed would have broke those users.
  • The library would still rely on global state; every miniredis instance created would call rand.Int63() and would all behave differently (in case a test creates more than one server, only has one of them use randomness, etc).

from miniredis.

alicebob avatar alicebob commented on May 23, 2024

from miniredis.

zikaeroh avatar zikaeroh commented on May 23, 2024

Sure, random is random, except that existing users may have already taken the advice of using the global seed in non parallel tests, and would otherwise be broken. (The fact that we can seed at all is really because it's only psuedorandom anyway, which is intended.)

from miniredis.

Related Issues (20)

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.