Random between 10 number using array

Get help using Construct 2

Post » Mon Jun 24, 2013 4:06 pm

Hello, I have a Question.
I want to make a button with a random between 1 and 10 number then store the result in an array. Then I click again the button and get a new random without the number that . this give me a new number that I want to store in the array too. I click again the button again with a random that will not include the both first two numbers (that are stored in the array) to the random results. I want to repeat this operation until I only have one number.
I know the theory to do this but I dont know how to write and use correctly the arrays for do it. Please if any one have some .capx example or some clear explanation of this answer my question. Thanks
B
6
S
2
Posts: 2
Reputation: 1,289

Post » Mon Jun 24, 2013 5:09 pm

Without testing and warranty, but basically this should work:

Create two one-dimensional arrays and a variable 'myrandom'. Fill the first one with the numbers 1 to 10. On button click get one number from the first array with
set myrandom to floor(random(array1.Width))
array2.Push front array1.at(myrandom)
array1.Delete myrandom

Do this until array1.Width = 1. Then the first array contains one number and array2 the other nine.
Image
B
24
S
8
G
10
Posts: 1,821
Reputation: 8,279

Post » Mon Jun 24, 2013 5:49 pm

Thank you Tulamide for your fast answer.
OK, this works but not exactly in the way that I would like.
There is the example.
TestArray1
The problem is that when I push the button with random numbers from array1, sometimes the number that is throws the random is repeated. I'm doing something wrong but I don't get it yet. If somebody can help me!
Thanksjavierov2013-06-24 20:28:48
B
6
S
2
Posts: 2
Reputation: 1,289


Return to How do I....?

Who is online

Users browsing this forum: dop2000, hao102a2 and 26 guests