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 (view all EZB hardware)
EZ-B V4 by EZ-Robot
EZ-B v4/2 robot controller: dual Cortex ARM, Wi-Fi, audio/video, 24 servo/digital ports, I2C/UART, camera and Synthiam ARC control for custom robots
Wi-Fi / USB
Servos 24
Camera
Audio
UART 3
I2C
ADC 8
Digital 24

Related Robot Skill (view all robot skills)
Script by Synthiam
Multi-language ARC Script: build, run and debug Blockly, JavaScript, EZ-Script or Python with Intellisense, run/save/load and Roboscratch support

ARC Pro

Upgrade to ARC Pro

Stay on the cutting edge of robotics with ARC Pro, guaranteeing that your robot is always ahead of the game.

Author Avatar
PRO
Synthiam
LinkedIn Thingiverse Twitter YouTube GitHub
#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

Author Avatar
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.

Author Avatar
PRO
Synthiam
LinkedIn Thingiverse Twitter YouTube GitHub
#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 ?

Author Avatar
PRO
Synthiam
LinkedIn Thingiverse Twitter YouTube GitHub
#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