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

0 favourites
  • 7 posts
From the Asset Store
The ultimate voice pack filled with 1,536 files of .......wav and mp3 of individual numbers, letters, and words (that go
  • 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.

  • 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???

    [attachment=0:3fcbkwy5][/attachment:3fcbkwy5]

    0*2 0

    1*2 2

    2*2 4

    3*2 6

    4*2 8

    etc

    31*2 62

    32*2 64

  • 2*floor(random(32)

    Thanks DUTOIT that works.

    2*floor(random(32)

    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.

  • 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))

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Yeah, it pretty much rounds it up or down to whole number.

    I thought floor rounded the number down?

    Is it different in Construct?

  • >

    >

    > 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

    exctract C2

    [quote:1q6iuy46]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
  • Again Thanks. MUCH Appreciated

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)