[Tutor] How to test function using random.randint()?
boB Stepp
robertvstepp at gmail.com
Sun Mar 20 22:18:43 EDT 2016
On Sun, Mar 20, 2016 at 8:44 PM, Ben Finney <ben+python at benfinney.id.au> wrote:
> boB Stepp <robertvstepp at gmail.com> writes:
>> Can I not use:
>>
>> if rng is None:
>> rng = random.Random()
>
> That will work.
>
> It unfortunately creates a new random.Random instance every time that
> line is executed, making the function waste a lot of time.
Ah, I should have thought of that. Thanks!
> So instead, you many want to create a module-level instance, and refer
> to that as the default.
I actually like this better anyway. At the moment I am focused on
randint, but later on I am certain I will be other methods of the
random module as this "fun" project develops.
boB
More information about the Tutor
mailing list