Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

Random not random

Hello I have a small problem with this part of the code:

alt text

In the editor, when testing on editor, i don't have any problem on random but after building the random is not random.

Product Version: Not Selected
more ▼

asked Aug 16 '14 at 11:13 PM in Blueprint Scripting

avatar image

11 3 5 5

avatar image v3ry Aug 17 '14 at 10:35 AM

I have try random stream and same result, very strange i have no problem on editor and but only in binnarie.

Thanks for help me, i m really disapointed.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

3 answers: sort voted first

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.

more ▼

answered Aug 17 '14 at 12:48 AM

avatar image

36.6k 931 169 1111

avatar image v3ry Aug 17 '14 at 06:46 AM

Yes i know random isn't really random but when i simulate orplay in editor, the number change every time. Why when its build, the number stay the same (in my case now 41) and try with other random in other blueprint and same. Random working on editor but not really on the builded version.

avatar image BlackDragon Sep 07 '14 at 12:01 AM

I have the exact same problem with the Shuffle node on an array. See: https://answers.unrealengine.com/questions/88297/shuffle-node-doesnt-work-after-shipping.html

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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.

more ▼

answered Sep 08 '14 at 08:57 AM

avatar image

1.8k 131 68 110

avatar image BlackDragon Sep 08 '14 at 09:21 PM

I even created a function in C++ to generate values, and made sure (using debug in Visual Studio), that I got new values everytime. Still, after packing the project and running in Windows, the numbers stay the same. I believe this must be a memory/garbage collection issue, or perhaps there is a proper way of cleaning up variables and such in Blueprint/C++ before the game exists?

Also tried using all kinds of combinations for blueprints using arrays, variables etc. Problem remains, the pseudorandom generators work, but only the first after packaging. After that the results seem "cached".

avatar image ronaldk Feb 02 '15 at 12:18 AM

Did anyone find a solution for random not being random?

avatar image VSZ May 09 '15 at 12:21 PM

Same issue here. I've tried every seeding trick I can think of, but in packaged builds random functions (frandinrange, frandinrangefromstream, etc) produce the same numbers every time. I found another thread which suggested seeding with srand(time(null)) [as the unreal random wrappers actually use srand underneath] but this didn't work for me either.

Did anyone get this to work yet?

PS: Everything works perfectly in the editor of course, only packaged builds are affected.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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.

more ▼

answered May 09 '15 at 04:24 PM

avatar image

944 24 29 55

avatar image funkstatic Jun 28 '15 at 08:47 PM

Any tips on how to fix this with blueprints?

my project currently does all of the random events inside of BPs... if not, is there some piece of code I could add that would work for all of those functions without having to recreate them?

avatar image VSZ Jun 28 '15 at 11:19 PM

You shouldn't have to rewrite your BP random events - however you do need to call srand(Time(NULL)) just once from somewhere in C++.

Off the top of my head this is the solution that I used: 1) Create a C++ singleton with a boolean variable that tracks whether you have already reset the seed. 2) Find an appropriate place (any of your main classes) to call srand(Time(NULL)) and set the singleton boolean to true to ensure no other component calls it again. For mine I used an InitializeComponent event of one of my actors.

It could be simpler yet - creating a custom gamemode (File->new C++ class -> derive from AGameMode), implementing event begin play and sticking srand(Time(NULL)) in there should work too but this did not work for me if I remember correctly.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question