Welcome to Synthiam!

The easiest way to program the most powerful robots. Use technologies by leading industry experts. ARC is a free-to-use robot programming software that makes servo automation, computer vision, autonomous navigation, and artificial intelligence easy.

Get Started
Asked — Edited

Random Answers To Questions Or Statements

Here's how I get random answers to questions and/or statements in EZ Builder. It's a simple way that can be expanded on as needed.

For example if I say - Goodbye
The program responds with a statement from this code;


$response = getrandomunique(0,3)
if($response =0)
Sayezb("have a good day")

elseif($response =1)
Sayezb("later man")

elseif($response = 2)
Sayezb("see you later, don't forget to turn me off")


You could have an unlimited number of responses if you wish.

I have several Speech Recognition statements that are setup this way, like;
Tell me a joke
Who am I ?
Who are you ?
Very good
or if I say "InMoov" it will answer with one of several statements
All of these are setup with the above code.

It's no AI but it does randomize the answers.
I also use this type of code in my Rock, Paper, Scissors program and some math scripts.


Upgrade to ARC Pro

Harnessing the power of ARC Pro, your robot can be more than just a simple automated machine.

@bhouston Ha! I used Google and got right to this post! I keep harrowing what you've plowed...! Thanks
One thing about the random commands I learned was that you need to have the GetRandom() or getrandomunique() set one number higher then the amount of responses you have listed. If not your last response will never get returned. For example if you have 3 responses you want chosen from you would write


I found I got a lot less repeated choices if used the getrandomunique() commend.
Wouldn't (0,3) produce four possible returns [0,1,2,3] ?
In code, array indexes usually start from 0 (and it doesn't matter if you start from one - just everything needs to shift one )
Though I see in Bob's code that he only is checking for 0, 1 and 2 -- hmm...

GetRandom(Min,Max) "returns a number between Min and Max"
I'm assuming that's inclusive so (1,4) will eventually produce [1,2,3,4] ?
Yes, you can start at zero as long as one of your responses are labeled zero. However like I said your getrandom needs to be one number higher then your last response. So (1,4) will eventually produce [1,2,3] .