I’m new to programming and new to Xojo. I call a normal-distributed pseudorandom number, “Normal”, several times, each in different functions, and then do some math on it. For example, in function 1:

`g(i,j)*Normal`

I would like to have a different pseudorandom number at each site in the array given by i and j, but that number needs to be the same in function 1 as in function 2 for the particular choice of i and j, if that makes sense. What would be the easiest way to do that?

Hi Samuel,

what is the range of possible values for i and j ? If the range is not too large, you could have a global function that accepts the i,j parameters and returns your “normal” random number. The function could also store the number in a dictionary. The logic in your function would be:

- check in dictionary if a number has been previously returned for the i,j parameters
- if so, return that same number
- if not, generate a new number, store it and return it

again, this depends on the possible values for i and j.

Thanks, Bruno. Sorry for these basic questions, but I’m a beginner at this:

How do I create a global function in Xojo? I made a public function named Dictionary under App>>Methods. Is this “global” then?

Also, how do I “check” a dictionary, and how do I “store” a number? I have the following pseudocode written so far:

```
For i=0 to Size-1
For j=0 to Size-1
if 'check number
Return 'number
else
'generate new number and store it
Return 'new number
end if
Next
Next
```

You can access your method with App.method name. If you want truly global then you need to create a module. Check the user reference on how to create and “store” properties, dictionaries and arrays.

@Bruno: Does the following work? I’m pretty shaky on the code as I’m still learning how to program.

```
Dim settings As New Dictionary
For i=0 to Size-1
For j=0 to Size-1
if settings.HasKey(Normal(i,j)) then // check in dictionary if a number has been previously returned for the i,j parameters
Return settings.Value(Normal(i,j)) // return that same number
else
Dim newNumber As Double // generate a new number
settings.Value("new")="Normal(i,j)"
newNumber = settings.Value("new") // store new number
Return newNumber // return new number
end if
Next
Next
```