# How do I randomly place numbers in an array?

Get help using Construct 2

### » Thu Feb 23, 2017 6:13 pm

0 multiplied by 0 is 0

That's okay, I need a single 0 as one of the results.

When the tutorial program is run, it locks up without displaying the results like normal. Same thing with choose(0,2,4,6,8,10). It will not give me a result. If i swap out the 0 like choose(1,2,4,6,8,10), it works, but no zero. I can get this to work though, choose("0","2","4","6","8","10").
B
47
S
20
G
6
Posts: 120
Reputation: 6,718

### » Thu Feb 23, 2017 6:22 pm

Matthew de wrote:
0 multiplied by 0 is 0

That's okay, I need a single 0 as one of the results.

When the tutorial program is run, it locks up without displaying the results like normal. Same thing with choose(0,2,4,6,8,10). It will not give me a result. If i swap out the 0 like choose(1,2,4,6,8,10), it works, but no zero. I can get this to work though, choose("0","2","4","6","8","10").

That is because you are trying to multiply by zero. Change it to 1 through 11 and then subtract one from the result and you will get your chosen range.
Banned User
B
29
S
7
G
58
Posts: 1,229
Reputation: 34,910

### » Thu Feb 23, 2017 6:34 pm

Where am I multiplying zero by zero? The only multiply I can see is, floor(Random(0,6))*2.

I can't get choose(0,2,4,6,8,10) to work either, I just want it to be able to pick the zero and give it to me.
B
47
S
20
G
6
Posts: 120
Reputation: 6,718

### » Thu Feb 23, 2017 6:44 pm

Matthew de wrote:Where am I multiplying zero by zero? The only multiply I can see is, floor(Random(0,6))*2.

I can't get choose(0,2,4,6,8,10) to work either, I just want it to be able to pick the zero and give it to me.

Random uses the first number in the range which you have as zero and you have 0*2 and you can't multiply 0.

Change range to 1,8 and then subtract 1 from the result and it will give you range 0 to 6.
Banned User
B
29
S
7
G
58
Posts: 1,229
Reputation: 34,910

### » Thu Feb 23, 2017 7:12 pm

But this does not:
floor(Random(0,6))*2
choose(0,2,4,6,8,10)

https://www.dropbox.com/s/c5h01uk2tybyc ... .capx?dl=0

Both work fine ?
B
33
S
18
G
29
Posts: 2,493
Reputation: 21,450

### » Fri Feb 24, 2017 6:43 am

I actually got the floor(Random(1,6))*2 working with subtraction. So I am able to achieve the result that I wanted.

However, I am still puzzled why choose(0,2,4,6,8,10) will not work for me. At this point I am just trying to understand the limitations.

You can see in the capx provided. Toggle between the two choose options to see the difference.
https://www.dropbox.com/s/jprcxp4vwn3iuo1/RandomNumbers.capx?dl=0
B
47
S
20
G
6
Posts: 120
Reputation: 6,718

### » Fri Feb 24, 2017 7:39 am

When choose(0,2,4,6,8,10) is the one running, it just gives me a black screen. Why can't it just choose 0 and enter it into the array?

On start of layout - array is not realy empty :

you can't place 0 -because array already contains number 0

so you first needs to fill the array with a different value

B
67
S
24
G
7
Posts: 1,519
Reputation: 11,104

### » Fri Feb 24, 2017 8:41 pm

Wow, that's the exact answer I was looking for! I did always assume that the array fields were completely empty and now it makes perfect sense.

Thank you everyone who help me figure this out.
B
47
S
20
G
6
Posts: 120
Reputation: 6,718

Previous