How to generate a random integer a single time?

I’m trying to create a function which gets a single random integer between 0 and 1023 and displays it in text form. With the setup I have now, when the text is displayed in game, the number changes every frame. Is there a way to set this up so the random number is only generated once? How would I do this?

119664-captureun.png

Assuming this is in a UMG Widget Blueprint and GetText1 is bound to a text lement.

Add the EventConstruct event to your UMG widget’s Event Graph. During the EventConstruct call RandomIntegerInRange and take it’s integer return value and store that in a class variable.

In your GetText1 function you will grab the class variable and use that as the input for ToText(int) instead of calling RandomIntegerInRange.

Thank you!

If this was the answer you were looking for could you mark it as accepted so others know this was the solution? :slight_smile:

You generate an array and fill it with data, then you take a random number of the array position between 0 and the amount of data you have :).
Hope it has fit.