random number help

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

So I know how to get random numbers, but I am having a problem, I am trying to get random numbers out of a dictionary. Like this:

Var randDictionary = {1:rand_range(0,2)}

func getRand():
     var Num = randDictionary[1]

how ever it returns the same number every time. Is there a better way to do this? If not I was thinking of having a array inside that dictionary that holds the random ranges and the function calls that, would that be the best way to do it?

It depends, are you trying to get a random number or a random number from a predefined set(like from a predefined set of numbers {0,5,8,13,15,16} )?

rustyStriker | 2020-05-03 16:21

:bust_in_silhouette: Reply From: deaton64

It’s returning the same number every time because you are randomizing after the dictionary value is set.

var randDictionary 

func _ready():
	randDictionary = {1:rand_range(0,2)}

func getRand():
	 var num = randDictionary[1]

thank you it worked!

stevepetoskey | 2020-05-03 16:50