Award
Congratulations DJ Sures, for answering the question and has received an EZ-Credit award! Share what you have learned and create a tutorial to help others by clicking here.

Putting Random Numbers In Order

Assistance Requested

Help bhouston with their question and receive $10 of EZ-Credit to get more robots and parts from our store. The following information was provided about their previous efforts searching tutorials for a resolution.

bhouston claims to have checked these sources:
 
#1

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

I have found a few conversations, tutorials and activities that may help with your question. Take a look at these links. I've sorted them by what I believe to be most relevant but that is not always the case as I'm still learning.


Also, consider reviewing the Learn section for informative lessons and activities. Check it out!


#2

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")

#3

Thanks DJ, I'll try that out.

#4

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!

#5

Awesome Smile

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 Grin