No announcement yet.

BUG or not ? Random Streams (with Make Random Streams node VS Random Streams variable)

  • Filter
  • Time
  • Show
Clear All
new posts

    BUG or not ? Random Streams (with Make Random Streams node VS Random Streams variable)


    From what i've read before and what I've tried, in Blueprints, the "randoms" nodes give a random value each time this node function is called.
    And the "randoms from stream" nodes give a random value once and then give the same value if we call it later and don't change the Initial Seed.

    Am I right or not ?

    Because after some tests, I found something weird.
    Here is my blueprint test, basically an event begin play, launching 4 Print String with the value randomly chosed. All the tests scenarii were played several times to be sure.

    Click image for larger version

Name:	BP_random_and_streams.PNG
Views:	122
Size:	120.9 KB
ID:	1415641

    1/ First test was with the node RANDOM INTEGER and the Max at 4.

    -> As expected, every PRINT return a different value (or not because no check for the previous value but often) because every time they're calling the function, this one get a random integer between 0 and 3.

    2/ Second test was with the node RANDOM INTEGER FROM STREAM with the Max at 4 as well. And a random stream variable with a fixed initial seed at 0.
    (the one currently working in this blueprint)

    -> I was expecting that all the PRINT nodes would return the same value first. But NO ! (more often than in the first test though but still weird).
    Moreover, I thought that when we change the INITIAL SEED of this variable, it would change the randoms value printed when i re-play the game, But NO !
    Is it normal ?!
    To get other values with this node, I had to create another variable (even if that one got the same initial seed)

    3/ Third test was with the node RANDOM INTEGER FROM STREAM with the same Max. And a MAKE RANDOM STREAM node linked to it and a fixed Initial Seed.

    -> This one work like I was expecting from a random from stream value. E.G. All the PRINT node return the same values.
    And If I change, the INITIAL SEED of the node MAKE RANDOM STREAM with another fixed value. Most of the time, when I re-play the game, I got another value randomly chosed but all the PRINT node return the same values

    To sum up, I guess the first test is correct !
    But what's wrong with the second and third ?
    I think the third is correct, but then what's wrong with the RANDOM STREAMS variable. Why is it not the same thant a MAKE RANDOM STREAM node ?
    Is it a bug ? Or just something I didn't understand yet ? (haha, it's possible) !

    PS : (My version is still 4.17.2 by the way)

    Random stream doesn't return the same value for one seed. For one seed, it will generate a sequence of random numbers and each time you go through RandomIntegerFromStream(), it will choose the next integer in this sequence.
    Moreover, the RandomStream structure will kind of store the index of the last requested number in the sequence. So you have to be carefull when you copy it : It will reset this index to 0. (You can pass the randomStream by ref to avoid this).
    My twitter :
    My UE4 assets :


      Yes thank you !
      It was what I was thinking of then. I think a good night of sleep helped me this last days to see this thing clearer. Haha !

      And, indeed, the MakeRandomFromStream create a new ref for this seed every time, so it's always go from the start of the sequence. That's why, it's always the same in my example because it always get the first number in the sequence in my example.
      And with the RandomStream variable, like you said, it goes through the same sequence but doesn't start every time I call it because it's the same ref (or variable) and is initialized once.

      Thank you for answering !

      Have a good day !