random and max, min values

For questions about using Classic.

Post » Fri Sep 04, 2009 2:34 pm

i'm trying to give my units various aim stats at the start of the game, which directly influence their firing accuracy.

I'm trying to generate a random value, but i want the lowest number to be 30 and the highest possible number 90, because in my game 100 and they'd never miss, 0 and they'd never hit anything.

So i tried somthing like,

min(90,max(30,random(100)))

it seems to come up with the min and max values a lot though.
B
37
S
19
G
18
Posts: 616
Reputation: 10,237

Post » Fri Sep 04, 2009 2:45 pm

You'll want to use 30+Random(60) if you want a random number from 30 to 90.
I think that's right, at least. I keep forgetting if random() does or does not go up to the number entered into it.
B
3
S
1
G
3
Posts: 82
Reputation: 1,189

Post » Fri Sep 04, 2009 2:51 pm

works a bit better thanks.

I was over complicating things lol :oops:
B
37
S
19
G
18
Posts: 616
Reputation: 10,237

Post » Fri Sep 04, 2009 6:02 pm

random(61) returns 0-60, so use 30+random(61) for a 30-90 spread.
B
25
S
3
G
6
Posts: 1,197
Reputation: 5,620


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 2 guests