fill array with random

0 favourites
  • 8 posts
From the Asset Store
Snare Drum Hits, Rolls & Fills (8 Drum Types) / 200 Unique Clips + 40 Loops / 11 minutes of audio
  • Hello.

    How i can fill array(10,1,1) with 10 results of random(1,10) function on start of layout?

    Thanks in advance.

  • I know there has to be a cleaner way to do this, and I could in Python in a single line, but I'm not sure how to simply write code in Construct. Regardless, this takes 1 event and some screen space. You could use the variables however you want, but this gives them the random amount at start of layout.

    Example capx

    {Edit:} Just refresh your browser when testing the layout to see the variable numbers change and you'll see that it works. I had to use int(random(1,10)) because it was giving me floats without the int() code, and you didn't ask how to get to the ten-thousandths of a random number between 1 and 10. <img src="smileys/smiley36.gif" border="0" align="middle">

    Figured I'd post an example in case someone sees it and knows a better way, then we can both clean up our code a bit. <img src="smileys/smiley2.gif" border="0" align="middle">

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks Dark, but i think that it can be done with construction like bellow

    System - On start of layout   Array - Set Variable to floor(random(1,10))

    - Array for each X element

    System - Every 1.0 sec        Text - Set text to ""&Array.Number

    - Array for each X element

  • Arg of course there's an easier way

    ArrayRandomValues.capx

  • Thnaks Yann

  • I knew there had to be a way to use "For" but didn't know how to get it in Constructor, thanks Yann.

    I have a question though. Since floor() always rounds down, is it possible to randomly get a result of 10 unless you miraculously random a 10.0000000? I noticed on my example I wasn't getting 10 either, but that's why I used int() instead of floor(). This question is also one reason why I participated.

  • Dark Savant: If you want to get 10 as a result of a random function, make it : random(11)

    This will return a value from 0 to 10.

    The last figure in a random() never gets reached.

  • Thank you! I was searching for such array example too.

    Another question ,Is this possible to make each value unique ?

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