Why not use a function rand()?

Why don’t we use a function rand()%XXX.Num(), but FMath::RandRange(0,10)?

My assumption would be that one has better performance and since its not security related then using the lighter one would make sense as long as it does what’s required.

It could also just have been whatever let’s just go with this one :smile:

A whole host of reasons

https://channel9.msdn.com/Events/GoingNative/2013/rand-Considered-Harmful

I believe it was also mentioned in the lecture that by using the RandRange from the UE4 API, you’re ensuring that it will work the same on multiple platforms, if you wanted to build your game for PC, Xbox, mobile, etc. Please correct me if I’m wrong about this though :slight_smile:

That should be correct.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms