Page 1 of 1

between a number...

PostPosted: Mon Jan 02, 2012 10:09 am
by BogdansB
hello,
How can I generate a number for example

if actor a collides with actor b -> variable c(100) minus (between 10 and 15)

so every time they collide, the variable gets 10,11,12,13,14 or 15 lesser...


thanks for now.

Re: between a number...

PostPosted: Mon Jan 02, 2012 7:53 pm
by schnellboot
Code: Select all
c-=10+rand(5);

Re: between a number...

PostPosted: Mon Jan 02, 2012 10:06 pm
by lcl
schnellboot wrote:
Code: Select all
c-=10+rand(5);

Actually:
Code: Select all
c -= (10 + rand(6));

Because rand() doesn't return the inputted value in maximum case, it returns one less (when we're talking about integers).

Re: between a number...

PostPosted: Mon Jan 02, 2012 10:12 pm
by schnellboot
lcl wrote:
schnellboot wrote:
Code: Select all
c-=10+rand(5);

Actually:
Code: Select all
c -= (10 + rand(6));

Because rand() doesn't return the inputted value in maximum case, it returns one less (when we're talking about integers).

lol thanks

Re: between a number...

PostPosted: Mon Jan 02, 2012 10:14 pm
by skydereign
But as a matter of clarity, it may make more sense to you to do this (they accomplish the same thing).
Code: Select all
c -= (10 + round(rand(5)));

That way it is clear that you are adding a random number from 0-5, since evidence by schnellboot's post it makes more sense to want to say 5 for random numbers 0-5. All round does is take the value you pass it and round according to the .5 rule (meaning rand(5) will round from 0-5 instead of being truncated to 0-4).