Question for Random Range?

While doing math with Random() is useful I was wondering if GDevelop had a simple RandomRange(##, ##)?

I can already do this with some crazy long winded math such as:
base (+ or -) a number (+ or -) (a Random(##)) but thats very annoying.

How do you make the – or rather what is the correct way of creating a range of two numbers to choose a random? in GDevelop.

The only way is to do this :

``MINIMUM + Random(MAXIMUM - MINIMUM)``
2 Likes

Ah simple to understand thanks. I guess I will use this to pass variables for more control.

what if there is no range instead there are number like (1,5,8)

You mean using Random(1,5,8) ??

What are you trying to do ?

I answered you about something similar to this original post here : [url]Random animation number? - #2 by Kink]

You want to randomly select a “discrete variable”? I mean select randomly a number from a set of isolated points?
Something like: Selecting a random number from {1,5,8} can return 1, 5 or 8?

If the sets has few numbers, you could do it manually:

[code]Conditions: No conditions
Actions: Do = Random(2) to variable “RandomIndex”

``````      Conditions: Variable "RandomIndex" is = 0
Actions: Do = 1 to variable "SelectedNumber"

Conditions: Variable "RandomIndex" is = 1
Actions: Do = 5 to variable "SelectedNumber"

Conditions: Variable "RandomIndex" is = 2
Actions: Do = 8 to variable "SelectedNumber"[/code]
``````

If there are many numbers, do it manually, number per number, would be tedious. But you can do it with structure variables too, just use a structure like this:

```Set 0 = 1 1 = 5 2 = 8```
Then just:

``Do = Variable(Set[ToString(Random(2))]) to variable "SelectedNumber"``

In both cases I’m just “mapping” the possible values from the Random(x) function to the values from the set (the values from Random(x) would be something like indices)

I don’t know If I am gonna use this logic for my game or not, I just asked out of curiosity but it might be help full for people. So what you should do is pin a forum here that states " First search for the similar forum, if it doesn’t answer your question, then write a forum. Thank you!"