France
Asked
Resolved Resolved by DJ Sures!

Equivalent Of Ezscript'S Sleeprandom(A,B) For Python ?

Hi, I used to use a lot SleepRandom(a,b) in my EZ-scripts to simulate random behaviors. I don't find the equivalent for Python scripting.

Outside of ARC, I use the "random" module (random module), but it does not seem to be present in ARC

import random

returns "No module named random".

Is there a way to achieve the same thing than SleepRandom with Python scripting in ARC, or is there a way to import the python random module? Thanks


Related Hardware EZ-B v4
Related Control Script

ARC Pro

Upgrade to ARC Pro

Stay at the forefront of robot programming innovation with ARC Pro, ensuring your robot is always equipped with the latest advancements.

PRO
Synthiam
#1  

Weird that it's _random.... hmm! Random :D


import _random

random = _random.Random()

print random.random()

#2  

Thanks @DJ ! I could have searching for it forever.... :D

PRO
USA
#3  

Quote:

Weird that it's _random....
_random works too but asfaik in Python 2 std library random exists.

User-inserted image

@DJ: You can make it work the same way. You will need to add an additional nuget package to your ARC project: User-inserted image

Regarding the _random:

Quote:

It is common practice to use a leading underscore for modules implemented in C.
The other reason is too avoid duplicated import names for the same functionality: _module1 can be called from CPython (C) and a module1 (py) wrapper can coexist and internally calls _module1.

Quote:

You will find this for several modules of the standard library.

Quote:

Typically, you should use module1 and not _module1.
Note: Quoted parts/statements are copied from the internet.

PRO
Synthiam
#4  

That’s good to know! Thanks ptp. I seem to be learning python as we go as well :)

#5  

It seems that I cannot use any other attribute than .Random

These following attributes, part of the random module, don't work:

random.uniform(1, 10) # Random float x, 1.0 <= x < 10.0 random.randint(1, 10) # Integer from 1 to 10, endpoints included random.randrange(0, 101, 2) # Even integer from 0 to 100 random.choice('abcdefghij') # Choose a random element

For example, I tried random.Randint , _random.randint , _random.Randint. Each of them returns

'module' object has no attribute 'randint'

Is it me who is missing something... Again ?

PRO
Synthiam
#6  

I added this to the next update. Stay tuned

#8  

I tested rapidly the new beta version before going to work and the "random" module works great, with all the attributes (and without the "underscore" :D) Thanks @DJ