Page 1 of 1

ACS: random() alternatives?

Posted: Sun Feb 17, 2013 11:14 pm
by Balrog
I think we all know that the RNG is complete shit. What are the accepted tricks to try and get more randomness from a random(x,y) ACS call?

RE: ACS: random() alternatives?

Posted: Sun Feb 17, 2013 11:17 pm
by Combinebobnt
Duel32 does it based on the game time passed.

RE: ACS: random() alternatives?

Posted: Sun Feb 17, 2013 11:25 pm
by Catastrophe
The above wouldn't work if you're executing a script at a specific time.

RE: ACS: random() alternatives?

Posted: Sun Feb 17, 2013 11:37 pm
by Ijon Tichy
The RNG is perfectly fine; it's just that its seed is shit. Of course we can't read from /dev/urandom or whatever the Winderps equivalent is, so no luck there.

Might want to pull in a bunch of CVars, throw some Random() number number in there, and run Random that many times as a pseudo-seed. Just an idea.

RE: ACS: random() alternatives?

Posted: Sun Feb 17, 2013 11:54 pm
by Qent
What are you using it for?

RE: ACS: random() alternatives?

Posted: Mon Feb 18, 2013 6:22 am
by Torr Samaho
Balrog wrote: I think we all know that the RNG is complete shit.
Are you referring to this issue?

RE: ACS: random() alternatives?

Posted: Mon Feb 18, 2013 8:39 am
by Cruduxy
Well you could do a hell load of random() and then find their average or median just an idea.

RE: ACS: random() alternatives?

Posted: Tue Feb 19, 2013 1:17 am
by Balrog
Qent wrote: What are you using it for?
Currently two calls in an OPEN script a random(1,14) call and a random(1000,1031) call 5 seconds later. (I've been meaning to make it a 64-player deal, but I've also got a clunky old inventory-based death manager that I don't want to strain any further) The second call gets repeated until it comes up with the TID of a extant player. The solution I'm thinking of based on Ijon's response is running random(1,500) random(1,dmflags%10+1) times, but I'm open to suggestions.
Torr Samaho wrote:
Balrog wrote: I think we all know that the RNG is complete shit.
Are you referring to this issue?
Maybe....

RE: ACS: random() alternatives?

Posted: Tue Feb 19, 2013 3:22 am
by Llewellyn
Assuming timer() is in Zandronum, can't you just do

Code: Select all

function int newRandom(int x, int y)
	return random(timer() + x, timer() + y) - timer();
Of course it would still be the same if you call it in OPEN I assume, as no time has elapsed (it's just random(x, y) then.)

If you're working with a server, you could mess with variables, and use them as a random seed, something like

Code: Select all

function int timerRandom(int x, int y)
	return random(timer() + x, timer() + y) - timer();
script 999 UNLOADING
	ConsoleCommand(StrParam(s:"set sv_oldseed ", d:timerRandom(timer(), GetCvar("sv_oldseed"))));
function int newRandom(int x, int y)
	return random(GetCvar("sv_oldseed") + x, GetCvar("sv_oldseed") + y) - GetCvar("sv_oldseed");

script 1 (void) // your script
{
	// Blah
	myRandom = newRandom(0, 31);
}
EDIT: You might have to check which one is bigger in 999, I dunno what would happen with like random(2, 1)

RE: ACS: random() alternatives?

Posted: Tue Feb 19, 2013 9:08 pm
by Torr Samaho
Balrog wrote:
Torr Samaho wrote: Are you referring to this issue?
Maybe....
You can easily tell whether this is your problem or not as the issue described in the ticket only affects how the RNG is initialized after a map change.

So far you just complained about the randomness of the function without indicating what exactly the problem you have with it is. Would you mind elaborating?

RE: ACS: random() alternatives?

Posted: Tue Feb 19, 2013 9:40 pm
by Balrog
The problem that I'm having is that certain results are coming up very often, while others aren't showing up at all. Interestingly, the one that almost never shows up - 14 on the random(1,14) call - shows up much more often in the "prepare to fight" LMS pre-game. Also, here's the script snippets that are relevant:

Code: Select all

Script 1 (void)
{
boss = random(1,12);
If(PlayerCount() >= 3){
boss = random(1,14);
}
terminate;
}

Script 2 OPEN
{
if(Timer()>0){
terminate;
}
ACS_Execute(1,0);
Delay(35*5);
ACS_Execute(3,0);
}

Script 3 (void)
{
BossPlayer= random(1000,1031);
if(LastBossPlayer == BossPlayer){
Delay(2);
restart;
}
if(LastBoss == boss){
ACS_Execute(1,0);
Delay(1);
restart;
}
/* Stuff here makes decisions on what to do and who to do it to based on the values of boss and BossPlayer, sets the values of LastBoss and LastBossPlayer to equal boss and BossPlayer, and then terminates if a sanity check shows that it was successful */
restart;
}
Yes, I made some mistakes in the previous posts. Sorry about that.

RE: ACS: random() alternatives?

Posted: Tue Feb 19, 2013 11:01 pm
by Synert
Hangman used to suffer from something related to random online- out of 500 words, it'd consistently use only ~6 of them every round.