'Retain original randomized number output for multiple function calls [duplicate]

I'm struggling with a particular issue in regards to having randomValues run as many times as in the range of TOTAL, but retain that information and not rerun again. Ideally have multiple functions call randomValues throughout but it is using the same 5 rows of randomValues from the first call. In the example below, no matter where I call randomValues() for the first time, it will remember those 3 values in 5 rows, so they can be called later on. Does that mean I store them somewhere for future use in the script?

import random
TOTAL = 5
def randomValues():
    a = random.randint(0,256)
    b = random.randint(0,256)
    c = random.randint(0,256)        
return a,b,c

for i in range(TOTAL): 
    # run this function for the first time, now remember those 3 values in 5 rows, so it can be called later on
    print ("valuesof35x" + str(i),randomValues())

# called later, and expect output to be the same as before
print ("valuesof35xagain",randomValues())
print ("valuesof35xagainagain",randomValues())

CURRENT OUTPUT

valuesof35x0 (55, 236, 30)
valuesof35x1 (59, 215, 108)
valuesof35x2 (207, 117, 210)
valuesof35x3 (127, 176, 112)
valuesof35x4 (185, 243, 218)
valuesof35xagain (84, 22, 196)
valuesof35xagainagain (251, 137, 208)

EXPECTED OUTPUT

valuesof35x0 (55, 236, 30)
valuesof35x1 (59, 215, 108)
valuesof35x2 (207, 117, 210)
valuesof35x3 (127, 176, 112)
valuesof35x4 (185, 243, 218)
valuesof35xagain (55, 236, 30)
valuesof35xagain (59, 215, 108)
valuesof35xagain (207, 117, 210)
valuesof35xagain (127, 176, 112)
valuesof35xagain (185, 243, 218)
valuesof35xagainagain (55, 236, 30)
valuesof35xagainagain (59, 215, 108)
valuesof35xagainagain (207, 117, 210)
valuesof35xagainagain (127, 176, 112)
valuesof35xagainagain (185, 243, 218)


Solution 1:[1]

I suggest that you save the values in a variable, probably a list. Then you can reuse those values whenever you want.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Code-Apprentice