# generate a random number every xx seconds with no repeat.

Get help using Construct 2

### » Sun May 07, 2017 9:04 am

Hello,

I've searched the web for this (and there's lots on scirra) but I just can't seem to get it working.

what I'm trying to do is:

generate a random number every xx seconds with no repeat.

"Textbox = random number
System Every 3.0 seconds > change the Random number (but no repeats)."

That's it> should be simple (I think I'm simple too)... I've tried Array count but it's not behaving as described.

B
4
S
1
Posts: 43
Reputation: 463

### » Sun May 07, 2017 10:01 am

Read a bit in the forum recently about the use (or rather uselessness) of the WHILE event ....

Excellent for this purpose:

https://www.dropbox.com/s/nmqs61lhbreo3 ... .capx?dl=0
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,562

### » Sun May 07, 2017 10:29 am

lennaert, you are AWESOME! Thanks very much

Roberto
B
4
S
1
Posts: 43
Reputation: 463

### » Sun May 07, 2017 10:40 am

@lennaert
@RobertoFreemano

That's a really nice example especially because you don't need to resort to arrays. One adjustment I'd make however is to:

int(random(FirstNumber,LastNumber))

I'd change this to:

floor(random(FirstNumber,LastNumber+1))

Otherwise the first and last number will be picked half as often as every other number.
B
16
S
7
G
3
Posts: 395
Reputation: 3,693

### » Sun May 07, 2017 10:44 am

@mekonbekon wrote:
Otherwise the first and last number will be picked half as often as every other number.

The concept of this is that it eventually every number in the range will get picked (even if its just at the end ^_^)
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,562

### » Sun May 07, 2017 10:48 am

@lennaert

Yes, I totally get that, but if you want to ensure that the order of picking is truly random then using int will more often push the first and last number to the back of the sequence; using floor should eliminate that bias.
B
16
S
7
G
3
Posts: 395
Reputation: 3,693

### » Sun May 07, 2017 10:51 am

@mekonbekon wrote:lennaert

Yes, I totally get that, but if you want to ensure that the order of picking is truly random then using int will more often push the first and last number to the back of the sequence; using floor should eliminate that bias.

Very true !!

Floor combined with the +1 would indeed make it more accurate (or rather random hehe)
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,562

### » Mon May 08, 2017 11:43 am

Can i add that there is an awesome plugin for that ?
plugin-smart-random_t163624
B
33
S
18
G
27
Posts: 2,444
Reputation: 20,352