Random not random
Hello I have a small problem with this part of the code:
In the editor, when testing on editor, i don't have any problem on random but after building the random is not random.
asked Aug 16 '14 at 11:13 PM in Blueprint Scripting
Because random in computers is really not random :p CPU can't generate random numbers, insted OS or application use battlefly effect kind of argorithms to generate random numbers based on input (seed), but if you use same input it will generate same stream of numbers. So my suspect is that both functions you use are using same seed and generate same numbers.
There other version of random nodes where you can input custom random stream based on custom seed, dont rember the exact name but search in libery "random" and you should find it, there also node that generate random stream which you will need to use.
Make sure you use a different Random Node for each different random generation you need. If you use one node and plug it into multiple other nodes then you run the risk of getting the same random number applied to all of them.
answered Sep 08 '14 at 08:57 AM
Okay, after several hours of troubleshooting I finally got random to work in packaged builds.
The basic idea is described in this thread thanks to RickDangerous, it took me a while to get it working though.
It looks like for packaged builds the seed used in FMath based random functions (which are just wrappers around the standard C++ rand/srand functions) gets set to some constant value each time you package the game. I thought the fix would be as simple as calling srand(Time(NULL)) from event begin play of my gamemode but I found that the seed gets reset to a constant value so reseeding it in event begin play is too early it seems.
The workaround I finally used was to call srand(Time(NULL)) from 'InitializeComponent' event of my component that needed random behavior, but I had to ensure that this is called once and only once - you do not want every single instance of that component to be resetting the seed repeatedly.
Frankly I wish the behavior of random functions in packaged games and editor mode would be consistent, but for now I'm happy with this technique/workaround and it is giving me reasonable results.
answered May 09 '15 at 04:24 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here