Community Question

I am writing code that selects 6 random numbers and then i want to put them/say them in numerical order. I've got the number selection working OK but then putting them in numerical order is the tricky part. I've got it so it will select the lowest number from all the numbers but I've hit a road block selecting the next lowest number.

Here's what I've got so far;

Code:


$number1 = Getrandomunique(1,50)
Say($number1)
:2
$number2 = Getrandomunique(1,50)
if ($number2 =$number1)
goto(2)
else
Say($number2)
endif
:3
$number3 = Getrandomunique(1,50)
if ($number3 = $number1 or $number3 = $number2)
goto(3)
else
Say($number3)
endif

:4
$number4 = Getrandomunique(1,50)
if ($number4 = $number1 or $number4 = $number2 or $number4 = $number3)
goto(4)
else
Say($number4)
endif

:5
$number5 = Getrandomunique(1,50)
if ($number5 = $number1 or $number5 = $number2 or $number5 = $number3 or $number5 = $number4)
goto(5)
else
Say($number5)
endif

:6
$number6 = Getrandomunique(1,50)
if ($number6 = $number1 or $number6 = $number2 or $number6 = $number3 or $number6 = $number4 or $number6 = $number5)
goto(6)
else
Say($number6)
endif


Print($number1)
Print($number2)
Print($number3)
Print($number4)
Print($number5)
Print($number6)
Print($number7)
#$response1 = X

#Say in order
#This part works
if($number1 < $number2 and $number1 < $number3 and $number1 < $number4 and $number1 < $number5 and $number1 < $number6)
say($number1)
$number1 = $numberA #not sure about this for the next number
print($numberA) #always prints a number not in the list
elseif($number2 < $number1 and $number2 < $number3 and $number2 < $number4 and $number2 < $number5 and $number2 < $number6)
Say($number2)
$number2 = $numberA
Print($numberA)
elseif($number3 < $number1 and $number3 < $number2 and $number3 < $number4 and $number3 < $number5 and $number3 < $number6)
Say($number3)
$number3 = $numberA
Print($numberA)
elseif($number4 < $number1 and $number4 < $number2 and $number4 < $number3 and $number4 < $number5 and $number4 < $number6)
Say($number4)
$number4 = $numberA
Print($numberA)
elseif($number5 < $number1 and $number5 < $number2 and $number5 < $number3 and $number5 < $number4 and $number5 < $number6)
Say($number5)
$number5 = $numberA
Print($numberA)
elseif($number6 < $number1 and $number6 < $number2 and $number6 < $number3 and $number6 < $number4 and $number6 < $number5)
Say($number6)
$number6 = $numberA
print($numberA)
endif

#this part is not working
if( $number1 > $numberA and $number1 < $number2 and $number1 < $number3 and $number1 < $number4 and $number1 < $number5 and $number1 < $number6)
say($number1)
elseif( $number2 > $numberA and $number2 < $number1 and $number2 < $number3 and $number2 < $number4 and $number2 < $number5 and $number2 < $number6 )
Say($number2)
Elseif( $number3 > $numberA and $number3 < $number1 and $number3 < $number2 and $number3 < $number4 and $number3 < $number5 and $number3 < $number6)
Say($number3)
#print($number)
endif


Any thoughts on how to get me going on the right track? I'm also hoping there may be a way the condense this.

Thanks

DJ Sures
Commented October 2015
Use this plugin that i created for you: http://www.ez-robot.com/EZ-Builder/Plugins/view/41

Here is an example of how to use it...

Code:


definearray($numbers, 6)

$numbers[0] = GetRandomUnique(0, 100)
$numbers[1] = GetRandomUnique(0, 100)
$numbers[2] = GetRandomUnique(0, 100)
$numbers[3] = GetRandomUnique(0, 100)
$numbers[4] = GetRandomUnique(0, 100)
$numbers[5] = GetRandomUnique(0, 100)

ControlCommand("SortArray", "$numbers", "ascending")

bhouston
Commented October 2015
Thanks DJ, I'll try that out.
bhouston
Commented October 2015
Thanks again DJ, by using the plugin you provided, I've got my code doing exactly what I wanted it to do. I learn something new here almost everyday!
DJ Sures
Commented October 2015
Awesome :)

I publish all my plugins OpenSource if anyone is interested to see how they're created to make their own. Many of you have been in EZ-Script for a long time and it's getting to the point where graduation to C# and making custom controls is near :D
Question
Avatarby bhouston
Published Wednesday, October 21, 2015