|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
I need a array with x numbers (1 to x) mixed. Like this:
Using 4 numbers (1 to 4), i need: array(1) = 3 array(2) = 2 array(3) = 4 array(4) = 1 This is random. I make this: Code:
x = 4 randomize array(1)=Int((x) * Rnd + 1) array(2)=Int((x) * Rnd + 1) while array(2) = array(1) array(2)=Int((x) * Rnd + 1) wend array(3)=Int((x) * Rnd + 1) while (array(3) = array(2)) or (array(3) = array(1)) array(3)=Int((x) * Rnd + 1) wend array(4)=Int((x) * Rnd + 1) while (array(4) = array(3)) or (array(4) = array(2)) or (array(4) = array(1)) array(4)=Int((x) * Rnd + 1) wend But, in this case, if x is a big number (like 100), the code will be very big too... Any idea? Thanks in advance Ricardo ![]() |
|
#2
|
|||
|
|||
|
lets see if i remember by bubble sort from my programming classes in school
PHP Code:
I just tested it and it works. if you do a search on google for bubble sort it will tell you how it works. Basicall it finds the lowest value and puts it in the 1st index position, then the second lowest and puts it in the second index position and so on. This is a pretty effective way to sort an array and pretty common. Last edited by imbrokn : May 20th, 2003 at 10:05 AM. |
|
#3
|
|||
|
|||
|
Sorry, I didn't express myself well.
I want a array with shuffled numbers, and not ordened numbers. The array contains numbers, 1 to x, ordered randomly (each time the order is different), like in my code (above). Thank you Regards, Ricardo |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ASP Programming > array sorting |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|