<p><a href="https://docs.python.org/3/library/random.html" rel="nofollow noreferrer">Python has this built in</a>. Or is there some reason you can't use it?</p>

CC BY-SA 4.0
2021-01-20T00:11:11.220Z
Thanks! I had simply not known about that function.
technicguy1
CC BY-SA 4.0
2021-01-20T00:34:34.343Z
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
CC BY-SA 4.0
2021-01-20T03:05:42.600Z
Links tend to break. Could you give a code example in your answer in case the link is no longer available?
David Lechner
CC BY-SA 4.0
2021-01-20T04:40:40.097Z
I'm guessing python.org is pretty safe.
RSchulz
CC BY-SA 4.0
2021-01-22T22:21:57.627Z
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 https://nbviewer.jupyter.org/github/arturomoncadatorres/lego-mindstorms/blob/main/examples/programs/random_images.ipynb?flush_cache=True
Arturo Moncada-Torres
CC BY-SA 4.0
2021-01-20T00:10:01.080Z
2021-01-20T00:10:01.080Z
RSchulz
<p>Under operators, there is a block &quot;Pick Random&quot; 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 ...</p>
<p><a href="https://i.sstatic.net/VK2Hc.png" rel="noreferrer"><img src="https://i.sstatic.net/VK2Hc.png" alt="enter image description here" /></a></p>

CC BY-SA 4.0
2021-01-19T23:46:31.120Z
I am actually using python, so this solution is not really applicable, but that's my fault for not saying so.
technicguy1
CC BY-SA 4.0
2021-01-19T09:57:32.227Z
2021-01-19T09:57:32.227Z
Michael Verschaeve
<p>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?</p>

<programming><spike-prime><robot-inventor><micropython>
How to get a random value in the Robot Inventor software (Python)
technicguy1
# How to get a random value in the Robot Inventor software (Python)

(Asked by: username_0 on 2021-01-19)

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?

**Tags:** programming, spike-prime, robot-inventor, micropython


---

## 2 answers

### Answer by username_1 on 2021-01-20. Score: 3 | Accepted answer

[Python has this built in](https://docs.python.org/3/library/random.html). Or is there some reason you can't use it?

> **Comments:**
> **username_0**: Thanks! I had simply not known about that function.  
> **username_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.  
> **username_2**: Links tend to break. Could you give a code example in your answer in case the link is no longer available?  
> **username_1**: I'm guessing python.org is pretty safe.  
> **username_3**: 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 https://nbviewer.jupyter.org/github/arturomoncadatorres/lego-mindstorms/blob/main/examples/programs/random_images.ipynb?flush_cache=True  

---

### Answer by username_4 on 2021-01-19. Score: 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](https://i.sstatic.net/VK2Hc.png)](https://i.sstatic.net/VK2Hc.png)

> **Comments:**
> **username_0**: I am actually using python, so this solution is not really applicable, but that's my fault for not saying so.  

---

