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;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")
endif
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.
Asked
— Edited
GetRandom(1,4)
or
getrandomunique(1,4)
I found I got a lot less repeated choices if used the getrandomunique() commend.
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] ?