Incremental Random Numbers

Get help using Construct 2

Post » Sun Oct 06, 2013 10:12 pm

I need to generate random numbers from 1 to 768 in increments of 32. Any ideas?

Thanks,

Steve
B
9
S
1
Posts: 8
Reputation: 1,043

Post » Sun Oct 06, 2013 10:24 pm

set number to floor(random(1,24))*32

that just leaves out 1, I guess..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Mon Oct 07, 2013 12:16 am

[QUOTE=LittleStain] set number to floor(random(1,24))*32

that just leaves out 1, I guess..[/QUOTE] This generates a number in range [32, 736], including both.

[QUOTE=ghoffman1982] I need to generate random numbers from 1 to 768 in increments of 32. Any ideas?[/QUOTE] You can't reach 768 in increments of 32 when starting at 1.

Either extend the range by 1 to 769, then it's
floor(random(25)) * 32 + 1

Or reduce the range by 31 to 737, then it's
floor(random(24)) * 32 + 1

Or start at 0, then it's
floor(random(25)) * 32tulamide2013-10-07 00:18:17
Image
B
24
S
8
G
10
Posts: 1,821
Reputation: 8,279

Post » Mon Oct 07, 2013 6:48 am

@tulamide,

You're right, slight miscalculation there.
Was aiming for your last one.
Added the 1 because I thought the 0 was unwanted, your explanation is much clearer.
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775


Return to How do I....?

Who is online

Users browsing this forum: Yahoo [Bot] and 29 guests