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?
2 Answers
Python has this built in. Or is there some reason you can't use it?
-
1
-
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.– RSchulzCommented 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? Commented Jan 20, 2021 at 3:05
-
-
1In 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/… Commented Jan 22, 2021 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 ...
-
1I am actually using python, so this solution is not really applicable, but that's my fault for not saying so. Commented Jan 19, 2021 at 23:46