# How do I generate a random number from a sequence?

0 favourites
• 6 posts
From the Asset Store
Easily generate many levels from a set of pre-built scenes (Construct 3 template)
• How do I generate a random number with from a set sequence?

For example, if I randomly want to assign the X value of a sprite, every 10 pixels of a range of 0 - 70), how would I go about doing that?

• Similar idea here:

• ## Try Construct 3

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

Construct 3 users don't see these ads
• I worked it out... I came here because I thought I was missing something, but I solved it with some very simple maths...

To solve my given example...

int(random(0,70))*10

I think this is the simplest way to solve it, no? I'll make a little example project tomorrow if people find it useful.

• int(random(0,8))*10

You were multiplying by 10 twice. This will give 0 to 70, with possible duplicates.

• And yes, of course, I always forget that random(a,b) includes a, but not b

• If you dont want to use a 3th party plugin, you can always use a Dictionary.

(personaly i very much like the BHT Smart Random plugin)

Clear the Dictionary

While

Compare 2 values > Dictionary.KeyCount ... is less then the amount of numbers you want (i suppose 7)

Local variable 'r' / number

..........actions ... set r to floor(random(0,8))*10