Is there something wrong with the Random function in UE5?

Hey Everyone,

I think I am losing my mind. I did a test using the Random Int in Range and found some of the results to defy logic. In this example code, whenever I press zero on the keyboard, it randomizes a number between 0 and 4. then using the Switch on Int, determines the output. Based on my code when the number = 0, it should print String ZERO!!!

But look at what happens with the results on my screenshots !

sample1 : generates 1 and nothing prints to screen so this is correct.
sample2 : generates 0 and nothing prints to screen. This is not correct. Should print ZERO!!!
sample3 : generates 1 and prints ZERO!!! to screen. This is not correct. Should not print anything.
sample4 : generates 1 and nothing prints to screen so this is correct.

That makes 2 correct responses and 2 incorrect responses… Please tell me I did something wrong somewhere…

code screenshot

sample1
sample1

sample2
sample2

sample3
sample3

sample4
sample4

Hi,
That will actually be generating two random numbers - one to print first, and then it creates another for the switch.

Generate the random number and set it in a local variable, then use that to prints it’s value and use for the switch.

Im an idiot… thanks man !

1 Like