Sorting Arrays numericly
Posted: Thu Oct 25, 2012 2:27 pm
OK after much google searching and testing ideas I still can't fix my problem, hoping someone here can help.
I am trying to create a lottery program for my advanced higher computing projecting livecode, it generates 6 random numbers from 1 to 49 then gives the user 2 chocies to choose his own numbers or have the computer generate numbers for him. I have it all well and working apart from 2 problems. Firstly it has repeating numbers sometimes, I have tried using another array of possible numbers it choosing a random number from that then deleteing that number the code for it is as follows
The second problem I have is it won't sort either of the arrays with the numbers properly, the closest i could get was a piece of code I got off a website that does sort it but sorts on only the first number, e.g. if I enter say 2,37,8,9,12,24 it should come up with 2,8,9,12,24,37 but instead it comes up with 12,2,24,37,8,9.
Please can someone help me.
I am trying to create a lottery program for my advanced higher computing projecting livecode, it generates 6 random numbers from 1 to 49 then gives the user 2 chocies to choose his own numbers or have the computer generate numbers for him. I have it all well and working apart from 2 problems. Firstly it has repeating numbers sometimes, I have tried using another array of possible numbers it choosing a random number from that then deleteing that number the code for it is as follows
Code: Select all
on Generate_users_numbers
local usersnumbers, possiblenumbers, numberoflines, arrayfile, arraypossiblenumbers
put url ("file:" & "C:/Users/Pincer/Desktop/Computing/Project/a.txt") into possiblenumbers
put the number of lines in possiblenumbers into numberoflines
repeat with loop = 1 to numberoflines
put line loop of possiblenumbers into arrayfile[loop]
end repeat
repeat with loop = 1 to 7
put random(49) into arraypossiblenumbers
put arrayfile[arraypossiblenumbers] into usersnumbers
repeat until usersnumbers is not empty then
put random(49) into arraypossiblenumbers
put arrayfile[arraypossiblenumbers] into usersnumbers
end repeat
put usersnumbers into array_users_numbers[loop]
delete variable arrayfile[arrayposiblenumbers]
end repeat
end Generate_users_numbers
Please can someone help me.