• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

C++ rand()% function

reisbro

Member
Joined
May 15, 2017
Messages
94
Solutions
1
Reaction score
7
EDIT: To generate random values use the uniform_random function in tools.h (remember to include it in the code you are working on)

As some of you may know, the rand()% function in c++ is not truly random. It repeats values and to change this you need to include time.h and srand(time(0));, but still it does not work properly (instead of giving a true random number, it gives increasing numbers until it reaches the top, and then it resets again.

How can I generate truly random values in the source codes? I'm on TFS 1.2, maybe the boost libraries have something? Thanks in advance!
 
Last edited:
Solution
tfs 1.2 provides a uniform_random function (see tools.h)
uniform_random(uint32_t min, uint32_t max)

usage would be the same way you use math.random(min, max) in lua
tfs 1.2 provides a uniform_random function (see tools.h)
uniform_random(uint32_t min, uint32_t max)

usage would be the same way you use math.random(min, max) in lua
 
Solution
tfs 1.2 provides a uniform_random function (see tools.h)
uniform_random(uint32_t min, uint32_t max)

usage would be the same way you use math.random(min, max) in lua
dude you are a lifesaver haha, if I win the lottery one day I will remember you, seriously you already answered like 10 questions I had
thanks!
 
Back
Top