2

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?

0

2 Answers 2

3

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

5
  • 1
    Thanks! I had simply not known about that function. Jan 20, 2021 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, 2021 at 0:34
  • Links tend to break. Could you give a code example in your answer in case the link is no longer available? Jan 20, 2021 at 3:05
  • I'm guessing python.org is pretty safe.
    – RSchulz
    Jan 20, 2021 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/… Jan 22, 2021 at 22:21
5

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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