Random Values Range

0 favourites
  • 5 posts
From the Asset Store
Easily generate many levels from a set of pre-built scenes (Construct 3 template)
  • Hey all, been trying to solve a problem involving random values, and have had a good search through the manual and forums but can't seem to figure this out...

    I'm trying to pick a random value between 1 and 3, and are currently using this which works fine (the 'Ceil' rounds the numbers up to whole decimals, which is what i want):

    Ceil(Random(3))

    But how do I use this to pick only 1 or 3 (i need to exclude 2). I thought it would be something like this, but it doesn't work:

    Ceil(Random(1,3))

    Thinking it would choose either 1 or 3...I think I'm barking up the wrong tree with this logic.

    Does anyone know a way to do this? Totally appreciate the help...

  • You're basically just choosing between two numbers so just do random(2) check if it's over 1 and return 3 else return 1.

    random(2) > 1 ? 3 : 1

  • Like this: CapX

    I would have used arrays and for loops but I'm not sure how to convert:

    var array = [1,3];

    for(var i = 0; i < 1; i++)

    {

    //Just a text function to output the text, use whatever you want

    console.log(array);

    }

    to the construct 2 equivalent.

  • You could use the choose(1,3) function.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks for the replies (and sorry for the late reply myself, I tried to reply last week but was getting an error on the forums).

    I used OddConfections suggestion of this "random(2) > 1 ? 3 : 1" which did exactly what I needed in the end.

    The 'choose(1,3) option sounds useful though. I didn't know about that function.

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