I am making a Python program with the LEGO Robot Inventor software which will, among other things, turn the robot a random amount periodically, which of course requires a random number. However, I could not find any way to do so. Is there any Python function which I could use to get a random number?


Python has this built in. Or is there some reason you can't use it?

  • 1
    Thanks! I had simply not known about that function. – technicguy1 Jan 20 at 0:11
  • Not every function from full python is necessarily available in every partial (or micro) python implementation, so I wanted to check first before going down a more elaborate route. – RSchulz Jan 20 at 0:34
  • Links tend to break. Could you give a code example in your answer in case the link is no longer available? – David Lechner Jan 20 at 3:05
  • I'm guessing python.org is pretty safe. – RSchulz Jan 20 at 4:40
  • 1
    In case anyone is looking for a concrete example using (Micro)Python's random, I created a small program that randomly displays images in the hub. You can find it here nbviewer.jupyter.org/github/arturomoncadatorres/lego-mindstorms/… – Arturo Moncada-Torres Jan 22 at 22:21

Under operators, there is a block "Pick Random" where you can specify to pick an integral number between x to y... x and y you can type... So for a random direction, set it between 0 and 359 degrees ...

enter image description here

  • I am actually using python, so this solution is not really applicable, but that's my fault for not saying so. – technicguy1 Jan 19 at 23:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.