Resolved by DJ Sures!

## Putting Random Numbers In Order

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;

``````
\$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 &lt; \$number2 and \$number1 &lt; \$number3 and \$number1 &lt; \$number4 and \$number1 &lt; \$number5 and \$number1 &lt; \$number6)
say(\$number1)
print(\$numberA) #always prints a number not in the list
elseif(\$number2 &lt; \$number1 and \$number2 &lt; \$number3 and \$number2 &lt; \$number4 and \$number2 &lt; \$number5 and \$number2 &lt; \$number6)
Say(\$number2)
\$number2 = \$numberA
Print(\$numberA)
elseif(\$number3 &lt; \$number1 and \$number3 &lt; \$number2 and \$number3 &lt; \$number4 and \$number3 &lt; \$number5 and \$number3 &lt; \$number6)
Say(\$number3)
\$number3 = \$numberA
Print(\$numberA)
elseif(\$number4 &lt; \$number1 and \$number4 &lt; \$number2 and \$number4 &lt; \$number3 and \$number4 &lt; \$number5 and \$number4 &lt; \$number6)
Say(\$number4)
\$number4 = \$numberA
Print(\$numberA)
elseif(\$number5 &lt; \$number1 and \$number5 &lt; \$number2 and \$number5 &lt; \$number3 and \$number5 &lt; \$number4 and \$number5 &lt; \$number6)
Say(\$number5)
\$number5 = \$numberA
Print(\$numberA)
elseif(\$number6 &lt; \$number1 and \$number6 &lt; \$number2 and \$number6 &lt; \$number3 and \$number6 &lt; \$number4 and \$number6 &lt; \$number5)
Say(\$number6)
\$number6 = \$numberA
print(\$numberA)
endif

#this part is not working
if( \$number1 &gt; \$numberA and \$number1 &lt; \$number2 and \$number1 &lt; \$number3 and \$number1 &lt; \$number4 and \$number1 &lt; \$number5 and \$number1 &lt; \$number6)
say(\$number1)
elseif( \$number2 &gt; \$numberA and \$number2 &lt; \$number1 and \$number2 &lt; \$number3 and \$number2 &lt; \$number4 and \$number2 &lt; \$number5 and \$number2 &lt; \$number6 )
Say(\$number2)
Elseif( \$number3 &gt; \$numberA and \$number3 &lt; \$number1 and \$number3 &lt; \$number2 and \$number3 &lt; \$number4 and \$number3 &lt; \$number5 and \$number3 &lt; \$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

With ARC Pro, your robot is not just a machine; it's your creative partner in the journey of technological exploration.

PRO
Synthiam
#1

Use this plugin that i created for you: https://synthiam.com/redirect/legacy?table=plugin&id=41

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

``````
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(&quot;SortArray&quot;, &quot;\$numbers&quot;, &quot;ascending&quot;)

``````
#2

Thanks DJ, I'll try that out.

#3

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!

PRO
Synthiam
#4

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