How to create random numbers/x,y variables using URscript 3.14

Hello! I am an university student just started using the universal robot simulation and i would like to implement a script code which allows me to create a random number [-200,200]. I am not that good in coding and I have tried this def random_coordinates(): x = rand(-200, 200) y = rand(-200, 200) but its not working. I am looking forward to any help i could get. Thanks very much for your answers!

I know that random() should work and yield your a number between 0 and 1. Then you should be able to scale your -200,200 to something usable and calculate a number inbetween with that. :slight_smile:

1 Like

To expand on what efn said - here’s a script I created a while back:

Random Number Generator - gives integer between 0 and 9999

def random_num():

return floor(random()*10000)

end

I used this back a couple versions of Polyscope, when we would have occasions where installation variables wouldn’t update. It displayed a random number to the operator, then had the program restart. If the displayed number changed, then all was well. If it was the same, then the variable wasn’t updating and the controller had to be restarted.
I think when we updated to 5.12 the problem went away.

2 Likes