[Microbit-Python] Micropython random numbers

David Whale david at thinkingbinaries.com
Wed Nov 25 09:40:35 EST 2015


There is indeed microbit.random()


Note that there is some evidence of a bug in the runtime random function at
the moment when I use it from Touch Develop, it's not very random, because
it is not seeded (I think).

My Dr Who Daleks game always shoots me on the first two goes, because the
random number sequence is, I think, the same every time.

It would be good if the first time random() was called it seeded it with
the running_time variable so that it was automatically randomized.

David.

___________________________________________________________
David Whale, B.Sc (Hons), MIET
*Software Engineer and IET Schools Liaison Officer, Essex*

email:  dwhale at theiet.org
twitter: @whaleygeek
blog:  blog.whaleygeek.co.uk

Co-author of the new book "Adventures in Minecraft" <http://amzn.to/ZGfxZG>
- lets get kids coding!


On 25 November 2015 at 14:15, Damien George <damien.p.george at gmail.com>
wrote:

> There is a microbit.random() function.
>
> On Wed, Nov 25, 2015 at 2:10 PM, Michael <sparks.m at gmail.com> wrote:
> > Check one of the sensors to see which one is changing lots, and take some
> > digits from that?
> >
> > (If you're shaking it and take values from the accelerometer with pauses
> > between from the compass you'll probably get values as random as shaking
> a
> > dice :-) )
> >
> >
> > Michael.
> >
> > On 25 November 2015 at 13:50, Martin O'Hanlon <martin at ohanlonweb.com>
> wrote:
> >>
> >> A microbit is on its way to me...  I've got an idea but it would be
> really
> >> useful to be able to create a random number, the equivalent of
> >> random.randint(0,5).
> >>
> >> From a quick look through Micropython's docs I dont think a random
> >> function is available.
> >>
> >> Has anyone got any inspired thoughts about how I might create a 'pseudo
> >> random number' using micropython.
> >>
> >> Mart
> >>
> >>
> >> --
> >>
> >> Blog - www.stuffaboutcode.com
> >>
> >> Twitter - @martinohanlon
> >>
> >>
> >> _______________________________________________
> >> Microbit mailing list
> >> Microbit at python.org
> >> https://mail.python.org/mailman/listinfo/microbit
> >>
> >
> >
> > _______________________________________________
> > Microbit mailing list
> > Microbit at python.org
> > https://mail.python.org/mailman/listinfo/microbit
> >
> _______________________________________________
> Microbit mailing list
> Microbit at python.org
> https://mail.python.org/mailman/listinfo/microbit
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/microbit/attachments/20151125/68889612/attachment-0001.html>


More information about the Microbit mailing list