[Tutor] How to test function using random.randint()?
Ben Finney
ben+python at benfinney.id.au
Sun Mar 20 09:18:01 EDT 2016
boB Stepp <robertvstepp at gmail.com> writes:
> On Sat, Mar 19, 2016 at 8:03 AM, Steven D'Aprano <steve at pearwood.info> wrote:
> > On Sat, Mar 19, 2016 at 04:05:58PM +1100, Ben Finney wrote:
> >> if rng is None:
> >> rng = random.random
> >
> > Typo: you want rng = random.randint.
No, I meant what I wrote. The ‘rng’ parameter is expected to be bound to
a RNG. If the caller has not specified a custom RNG instance, we bind
‘rng’ to the standard RNG instance found at ‘random.random’.
> >> result = rng.randint(1, num_sides)
> >
> > And here you just want result = rng(1, num_sides). Otherwise you're
> > trying to call random.randint.randint.
>
> And then this statement would be correct as Ben wrote it.
Unlike some other examples I have posted, I actually bothered to
demonstrate this working as expected before posting it :-)
> Ben, please chime in if I have got it wrong.
You have it right, Bob.
--
\ “If consumers even know there's a DRM, what it is, and how it |
`\ works, we've already failed.” —Peter Lee, Disney corporation, |
_o__) 2005 |
Ben Finney
More information about the Tutor
mailing list