EZ-Builder Release 2012.11.28.00

Download and install the latest EZ-Builder robot programming software to experience these updates.

Download EZ-Builder
This is a small release regarding Random features of your robot. There was a recent discussion about what "random" really means in programming. Random() is a common function used in computers making unpredictable decisions. However, if you wish to write your own routines for random behavior, perhaps Random() isn't optimized.

As a disclaimer: We encourage people to use the Personality Generator, which uses an algorithm based on trending - not random.

So, the solution? After a bit of brain storming, I came up with a new Random function called GetRandomUnique(). This new function tries to make the returned value unique from the last. This is not a Personality Generator replacement, but it will make your robot much better behaved.

Changes:
- EZ-Script controls can be resized
- New EZ-Script command: GetRandomUnique()
- EZ-Script compiler optimizations

Here is an Example Project displaying the differences between Random() and GetRandomUnique(): Example-Script-RandomNumberFunctions.EZB

User-inserted image
#13  
@DJ, I just tried the SendSerial tonight with the latest release, it's working without locking up, and I can now send complete sentences without any problems.

You must of done something or is it me?


Thanks
Synthiam
#14  
@charleybot nothing was changed. glad to hear it works for what ever magical reason:)
Canada
#15  
Those sneaky little Roboticist elves working away at night again;)
#16  
Hi all,

Yep after 4 years I'm finally getting to the point where I'm working in random routine responses into my robot. I ran into an odd occurrence with my scripting so I dug up this old thread talking about this function.

Anyway, I've written a script that will randomly choose a sound clip from a randomly chosen actor. In the actual script, each actor is divided into their own subsection. In this actor's section are commands to play sound files that will be randomly chosen. Clear as mud? :)

The problem is if I have a list of choices the last on in the list will never get picked. This happens with either the GetRandomUnique() or the GetRandom() command.

For example if I've written $response = GetRandomUnique(1,4) the 4th number will never generate.

I just had a thought; Is it the way I'm starting my numbering system? Do I need to start with 0?

Here's my code so far. Works pretty good except I can never get the last choice on the list to get picked. Any ideas? Thanks.

Code:


# Choose a random actor and speak a phrase before going to their subsection.
$response = GetRandomUnique(1,3)

# Response depending on random number
if ($response = 1)
ControlCommand("Soundboard v4", Track_61)
Sleep(2000)
Goto(Dr_Smith)
ELSEif ($response = 2)
ControlCommand("Soundboard v4", Track_72)
Sleep(2000)
Goto(R2D2)
ELSEif ($response = 3)
ControlCommand("Soundboard v4", Track_77)
Sleep(2000)
Goto(Will)
endif

# -----------------------------------------
:Dr_Smith
# Speak a random phrase from 1 to 10
$DRresponse = GetRandomUnique(1,10)

# Response depending on random number
if ($DRresponse = 1)
ControlCommand("Soundboard v4", Track_62)
ELSEif ($DRresponse = 2)
ControlCommand("Soundboard v4", Track_63)
ELSEif ($DRresponse = 3)
ControlCommand("Soundboard v4", Track_64)
ELSEif ($DRresponse = 4)
ControlCommand("Soundboard v4", Track_65)
ELSEif ($DRresponse = 5)
ControlCommand("Soundboard v4", Track_66)
ELSEif ($DRresponse = 6)
ControlCommand("Soundboard v4", Track_67)
ELSEif ($DRresponse = 7)
ControlCommand("Soundboard v4", Track_68)
ELSEif ($DRresponse = 8)
ControlCommand("Soundboard v4", Track_69)
ELSEif ($DRresponse = 9)
ControlCommand("Soundboard v4", Track_70)
ELSEif ($DRresponse = 10)
ControlCommand("Soundboard v4", Track_71)
endif
Halt()
#------------------------------------------------------------------

:R2D2
# Speak a random phrase from 1 to 4
$SWresponse = GetRandomUnique(1,4)

# Response depending on random number
if ($SWresponse = 1)
ControlCommand("Soundboard v4", Track_73)
ELSEif ($SWresponse = 2)
ControlCommand("Soundboard v4", Track_74)
ELSEif ($SWresponse = 3)
ControlCommand("Soundboard v4", Track_75)
ELSEif ($SWresponse = 4)
ControlCommand("Soundboard v4", Track_76)
endif
Halt()
#------------------------------------------------------------------

:Will
ControlCommand("Soundboard v4", Track_78)
Halt()
Synthiam
#17  
As per Random() functions in programming of all languages that I am aware of, the range of return values includes minValue but not maxValue.

So, to randomly get a number between 1 and 4, you would use GetRandomUnique(1,5)

Code:


# Choose a random actor and speak a phrase before going to their subsection.
$response = GetRandomUnique(1,4)

# Response depending on random number
if ($response = 1)
ControlCommand("Soundboard v4", Track_61)
Sleep(2000)
Goto(Dr_Smith)
ELSEif ($response = 2)
ControlCommand("Soundboard v4", Track_72)
Sleep(2000)
Goto(R2D2)
ELSEif ($response = 3)
ControlCommand("Soundboard v4", Track_77)
Sleep(2000)
Goto(Will)
endif

# -----------------------------------------
:Dr_Smith
# Speak a random phrase from 1 to 10
$DRresponse = GetRandomUnique(1,11)

# Response depending on random number
if ($DRresponse = 1)
ControlCommand("Soundboard v4", Track_62)
ELSEif ($DRresponse = 2)
ControlCommand("Soundboard v4", Track_63)
ELSEif ($DRresponse = 3)
ControlCommand("Soundboard v4", Track_64)
ELSEif ($DRresponse = 4)
ControlCommand("Soundboard v4", Track_65)
ELSEif ($DRresponse = 5)
ControlCommand("Soundboard v4", Track_66)
ELSEif ($DRresponse = 6)
ControlCommand("Soundboard v4", Track_67)
ELSEif ($DRresponse = 7)
ControlCommand("Soundboard v4", Track_68)
ELSEif ($DRresponse = 8)
ControlCommand("Soundboard v4", Track_69)
ELSEif ($DRresponse = 9)
ControlCommand("Soundboard v4", Track_70)
ELSEif ($DRresponse = 10)
ControlCommand("Soundboard v4", Track_71)
endif
Halt()
#------------------------------------------------------------------

:R2D2
# Speak a random phrase from 1 to 4
$SWresponse = GetRandomUnique(1,5)

# Response depending on random number
if ($SWresponse = 1)
ControlCommand("Soundboard v4", Track_73)
ELSEif ($SWresponse = 2)
ControlCommand("Soundboard v4", Track_74)
ELSEif ($SWresponse = 3)
ControlCommand("Soundboard v4", Track_75)
ELSEif ($SWresponse = 4)
ControlCommand("Soundboard v4", Track_76)
endif
Halt()
#------------------------------------------------------------------

:Will
ControlCommand("Soundboard v4", Track_78)
Halt()