How do I generate INT even numbers only **SOLVED**

Get help using Construct 2

Post » Wed Oct 08, 2014 9:47 am

Hi
I am working with the formula int(random(0,64)) for example,
but
I would like only even numbers to be generated.

Anyone out there know the equation that will work in C2?

I have already installed a 'Brute Force' correction method via
comparing two values and upping by one the number if an odd value is generated
for example::: if YYYY equals 7 add 1
this means
for the above int(random(0,64)), I need 32 checks to correct for an odd number.

I was wondering if there was a actual formula that generates only Even numbers?

Thanks for looking.
Last edited by producermark11 on Wed Oct 08, 2014 1:21 pm, edited 1 time in total.
B
36
S
10
G
4
Posts: 250
Reputation: 7,963

Post » Wed Oct 08, 2014 9:55 am

Even number means it can be divided by 2

So...
2*floor(random(32)

32*2 is 64 that is why.

attached is a repeat 100 to see if it works???
testmeout.capx


0*2 0
1*2 2
2*2 4
3*2 6
4*2 8
etc
31*2 62
32*2 64
You do not have the required permissions to view the files attached to this post.
You think you can do these things, but you can't, Nemo!
Just keep reading.
Just keep learning.
B
65
S
16
G
9
Posts: 1,429
Reputation: 12,718

Post » Wed Oct 08, 2014 1:18 pm

2*floor(random(32)

Thanks @DUTOIT that works.

2*floor(random(32)
:D

I never heard of floor being used before, so I googled it.

Wikipedia:
In mathematics and computer science, the floor and ceiling functions map a real number to the largest previous or the smallest following integer, respectively. More precisely, floor(x) = \lfloor x\rfloor is the largest integer not greater than x and ceiling(x) = \lceil x \rceil is the smallest integer not less than x.[1]

Again Thanks.
B
36
S
10
G
4
Posts: 250
Reputation: 7,963

Post » Wed Oct 08, 2014 1:45 pm

producermark11 wrote:I never heard of floor being used before, so I googled it.

Yeah, it pretty much rounds it up or down to whole number.

Bookmark this page. Google those too, clamp, float, right, left, find etc etc etc

Will simplify your life ;)


oops, forgot to close the bracket 2*floor(random(32))
You think you can do these things, but you can't, Nemo!
Just keep reading.
Just keep learning.
B
65
S
16
G
9
Posts: 1,429
Reputation: 12,718

Post » Wed Oct 08, 2014 1:58 pm

DUTOIT wrote:
Yeah, it pretty much rounds it up or down to whole number.



I thought floor rounded the number down?

Is it different in Construct?
B
11
S
2
Posts: 46
Reputation: 739

Post » Wed Oct 08, 2014 2:02 pm

maxxscape wrote:
DUTOIT wrote:
Yeah, it pretty much rounds it up or down to whole number.



I thought floor rounded the number down?

Is it different in Construct?


Lol, you are a 100% right... my bad :oops:

exctract C2
floor(x) Round down x e.g. floor(5.9) = 5


I was thinking round which is better to use in most cases... agggh! long day ;)


Sidenote:
==========================================================================
Edit, for general info: I said most cases, here is why I went for floor:
Range---------floor() -------- round()

[0, 1)--------------0 ------------- 0 or 1
[1, 2)-------------- 1 -------------- 1 or 2
[2, 3)-------------- 2 -------------- 2 or 3
... -------------- ... -------------- ...
[9, 10) -------------- 9 -------------- 9 or 10

It is was more predictable ;)
You think you can do these things, but you can't, Nemo!
Just keep reading.
Just keep learning.
B
65
S
16
G
9
Posts: 1,429
Reputation: 12,718

Post » Wed Oct 08, 2014 3:21 pm

Again Thanks. MUCH Appreciated
B
36
S
10
G
4
Posts: 250
Reputation: 7,963


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 7 guests