AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   random_num .. not that random (https://forums.alliedmods.net/showthread.php?t=253736)

Cv3 12-27-2014 13:57

random_num .. not that random
 
Okay I pick up few rows from a text file and have to select 1 in random, I used

PHP Code:

random_num(0,TOTALROWS 1

the problem occurs, I have 5 servers selecting from the same file. And they are not supposed to "random" select the same thing. At all this random_num thing is not that random .. how can I randomize it completely ?

fysiks 12-27-2014 19:23

Re: random_num .. not that random
 
Quote:

Originally Posted by Cv3 (Post 2240725)
PHP Code:

random_num(0,TOTALROWS 1


If you are using it to select a random index for an array, you should use random(sizeof(my_array)).


Quote:

Originally Posted by Cv3 (Post 2240725)
the problem occurs, I have 5 servers selecting from the same file. And they are not supposed to "random" select the same thing.

What you describe here is NOT purely random.

Quote:

Originally Posted by Cv3 (Post 2240725)
At all this random_num thing is not that random .. how can I randomize it completely ?

You just said that you didn't want a random selection because you don't want your other servers to get the same number. This is how random works. There is a chance that you will get the same number every single time that the function is used.

random() and random_num() is the most random you can get with AMX Mod X. Other computer-based random functions won't be much, if any, better than these. If you want truly random, start flipping coins (but you don't want random because you stated that in your post).

In conclusion, if you want help, you will need to describe better your situation and what you really want (not what you think you need to get what you want; aka "The XY Problem").

EDIT: This might be helpful: [HOW TO] Retrieve random values from an array without retreiving the same twice

Cv3 12-29-2014 21:05

Re: random_num .. not that random
 
I figured it out, the problem was actialy the timing. All the servers are launched using a bash script at the same time, after adding a delay in the loop it fixed itself. No need to modify the plugin *whew*

I think it couldn't be described better, the way that every 'randomizing' function works is by using some hardware timing and when I launch them all 5 at the same time it stucks like that.


All times are GMT -4. The time now is 15:17.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.