How can i make a robot turn a random number from a particular set of values

I hope this question makes sense. I was up all night. I can’t figure it out.

starting in the center of the standard grid map, I want my robot randomly turning at one of these headings:

0°, 45°, 90°, 145°, 180°, -145°, -90°, -45°.

Shouldn’t that be 135 and -135 degrees? If so, this just got easier.

Take a random integer from -4 to +4, multiply by 45. Done.

Or if the code does not support that range, then 0-12, subtract 4, multiply by 45. Done.

That only works because the desired numbers are evenly spread in this case.

For the reference of future forum users who might find this topic via the search bar, an alternate method that would work even if the numbers aren’t spread evenly is to make a variable and assign/map different values of it to the different headings you want. Then, have that variable randomize and the random number corresponds to a heading so you would have the robot turn to the corresponding heading.

How do I assign a variable different values

The simplest way is to use if statements and have something like this:

*this is my best imitation of how it would look with block coding

if (randomized variable = 1) [
turn to heading (0) (degrees)
]
if (randomized variable = 2) [
turn to heading (45) (degrees)
]

(this would have an if statement for each desired heading in the full version, as well as actually randomizing the variable before the if statements)

You can make a list, denoted as
angles=[0,45,90,145,180,-145,-90,-45] in python, or


then,