# random numbers no duplicates zero always last!

Get help using Construct 2

### » Tue Jan 22, 2013 12:00 pm

Hi

My eyes are strained and head aches...
I have this piece of random number with no duplicates code in another project... it works BUT ZERO is ALWAYS last!
What am i missing or should i do?

many thanks for any help that can be given

https://www.dropbox.com/sh/rtf1ilgtg5mnrhg/A4i7lG7zV2construct2dsjp2013-01-22 12:06:21
B
5
Posts: 14
Reputation: 453

### » Tue Jan 22, 2013 12:45 pm

B
99
S
35
G
29
Posts: 3,139
Reputation: 28,426

### » Tue Jan 22, 2013 12:54 pm

sorry new here...

https://www.dropbox.com/s/tdf4auara29znts/again.capx
many thanks
D
B
5
Posts: 14
Reputation: 453

### » Tue Jan 22, 2013 1:33 pm

Change "while i <= Array.width"
to "while i < Array.Width"
B
24
S
9
G
7
Posts: 756
Reputation: 7,342

### » Tue Jan 22, 2013 1:42 pm

Hi Vee41
Sadly I tried that before, that only gives me 10 numbers

i.e 1,2,3,4,5,6,7,8,9 and 10...

i need a total of 11 random non duplicating numbers including the Zero 0, but not always last... :(

I am probably missing something really simple...but?

D
B
5
Posts: 14
Reputation: 453

### » Tue Jan 22, 2013 1:54 pm

Well width of your array is only 10, no way you can fit 11 numbers into that :)

EDIT: So set your array width to 11, adjust the limit of numbers accordingly and do the change I described before.vee412013-01-22 13:56:26
B
24
S
9
G
7
Posts: 756
Reputation: 7,342

### » Tue Jan 22, 2013 2:19 pm

Vee
I am really really tired, so bear with me....

My knowledge is weak, so at the start i set array width to 11 (because i wanted 11 numbers), but i then got 12 numbers... ? which is 1 too many!

so to test this i set my array width to

2,i get a variable at 0,1,2 thus 3 numbers
5,i get a variable at 0,1,2,3,4 thus 6 numbers
10,i get a variable at 0,1,2,3,4,5,6,7,8,9,10 thus 11 numbers as i wish...
so i guess it starts at zero??????

I have added a text box to print out every number generated by the randomNumber code, it SHOWS zero's appearing YET not being accepted into the array...? it seems to wait until it has all the rest of the numbers then add a zero at the end.

https://www.dropbox.com/s/1noog3xyanq9iwz/screenshot.jpg
B
5
Posts: 14
Reputation: 453

### » Tue Jan 22, 2013 2:37 pm

Here you go: Fixed version

The array was initialized with 0's so it never gets randomed and random nubmer choosing stage. I initialize the array with -1 so it's a bit more intuitive to use now :)
B
24
S
9
G
7
Posts: 756
Reputation: 7,342

### » Tue Jan 22, 2013 3:13 pm

vee many many thanks

I did need the array to be 11 then, but fill it with something other than the numbers i needed, before refiling it with the randomNumbers , yes?

I think i understand, hahahahha

many thnaks again
D
B
5
Posts: 14
Reputation: 453

### » Tue Jan 22, 2013 3:24 pm

[QUOTE=construct2dsjp]
I did need the array to be 11 then, but fill it with something other than the numbers i needed, before refiling it with the randomNumbers , yes?
[/QUOTE]

Exactly :)

Every value in array is 0 until you set it as something else, thus the randomizing part never randomed 0.
B
24
S
9
G
7
Posts: 756
Reputation: 7,342

Next

### Who is online

Users browsing this forum: No registered users and 16 guests