How to exclude numbers from the randi() function

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By soulldev

In GDScript, is it possible to exclude a set of numbers (that’s not in range) from the randi() function ?

:bust_in_silhouette: Reply From: volzhs

there’s no functionality for it.
that is a very corner case, and you should make a logic for your need.

:bust_in_silhouette: Reply From: MZmuda

Do you mean something like this?

var MaxNumber = 20
var BadNumbers = [0, 2, 3, 5, 7, 11, 13, 17]
var aNumber = 0
while (aNumber in BadNumbers) : aNumber = randi()%MaxNumber

Exactly what i want, thank you!

soulldev | 2019-05-01 07:23

You’re very welcome!!!

MZmuda | 2019-05-01 23:50