ACS: random() alternatives?

Discuss all aspects related to modding Zandronum here.
Post Reply
User avatar
Balrog
Forum Regular
Posts: 215
Joined: Fri Aug 10, 2012 11:16 am

ACS: random() alternatives?

#1

Post by Balrog » Sun Feb 17, 2013 11:14 pm

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?

Code: Select all

[15:53:14] balrog: one day, the original mm8bdm devteam from mfggu and i will meet in valhalla and we will be friends

Code: Select all

<ijon>well fuk
<ijon>guess I gotta suck dicks now

Code: Select all

(18:13:17)<Mayrine>i dont have to learnt anything about ACS

User avatar
Combinebobnt
Retired Staff / Community Team Member
Posts: 1906
Joined: Mon Jun 04, 2012 3:37 am
Location: Earth
Contact:

RE: ACS: random() alternatives?

#2

Post by Combinebobnt » Sun Feb 17, 2013 11:17 pm

Duel32 does it based on the game time passed.

Catastrophe
Retired Staff / Community Team Member
Posts: 2571
Joined: Sat Jun 02, 2012 2:44 am

RE: ACS: random() alternatives?

#3

Post by Catastrophe » Sun Feb 17, 2013 11:25 pm

The above wouldn't work if you're executing a script at a specific time.

Ijon Tichy
Frequent Poster Miles card holder
Posts: 901
Joined: Mon Jun 04, 2012 5:07 am

RE: ACS: random() alternatives?

#4

Post by Ijon Tichy » Sun Feb 17, 2013 11:37 pm

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.

Qent
Retired Staff / Community Team Member
Posts: 1424
Joined: Tue May 29, 2012 7:56 pm
Contact:

RE: ACS: random() alternatives?

#5

Post by Qent » Sun Feb 17, 2013 11:54 pm

What are you using it for?

User avatar
Torr Samaho
Lead Developer
Posts: 1543
Joined: Fri May 25, 2012 6:03 pm
Location: Germany

RE: ACS: random() alternatives?

#6

Post by Torr Samaho » Mon Feb 18, 2013 6:22 am

Balrog wrote: I think we all know that the RNG is complete shit.
Are you referring to this issue?

Cruduxy
Zandrone
Posts: 1059
Joined: Fri Jun 08, 2012 4:24 pm

RE: ACS: random() alternatives?

#7

Post by Cruduxy » Mon Feb 18, 2013 8:39 am

Well you could do a hell load of random() and then find their average or median just an idea.
[][][][][][][][][][][][][][][]
Nothing to see here
[][][][][][][][][][][][][][][]

User avatar
Balrog
Forum Regular
Posts: 215
Joined: Fri Aug 10, 2012 11:16 am

RE: ACS: random() alternatives?

#8

Post by Balrog » Tue Feb 19, 2013 1:17 am

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....
Last edited by Balrog on Tue Feb 19, 2013 1:18 am, edited 1 time in total.

Code: Select all

[15:53:14] balrog: one day, the original mm8bdm devteam from mfggu and i will meet in valhalla and we will be friends

Code: Select all

<ijon>well fuk
<ijon>guess I gotta suck dicks now

Code: Select all

(18:13:17)<Mayrine>i dont have to learnt anything about ACS

Llewellyn
Forum Regular
Posts: 578
Joined: Mon Jul 02, 2012 7:12 am

RE: ACS: random() alternatives?

#9

Post by Llewellyn » Tue Feb 19, 2013 3:22 am

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)
Last edited by Llewellyn on Tue Feb 19, 2013 3:39 am, edited 1 time in total.

User avatar
Torr Samaho
Lead Developer
Posts: 1543
Joined: Fri May 25, 2012 6:03 pm
Location: Germany

RE: ACS: random() alternatives?

#10

Post by Torr Samaho » Tue Feb 19, 2013 9:08 pm

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?

User avatar
Balrog
Forum Regular
Posts: 215
Joined: Fri Aug 10, 2012 11:16 am

RE: ACS: random() alternatives?

#11

Post by Balrog » Tue Feb 19, 2013 9:40 pm

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.
Last edited by Balrog on Wed Feb 20, 2013 4:53 pm, edited 1 time in total.

Code: Select all

[15:53:14] balrog: one day, the original mm8bdm devteam from mfggu and i will meet in valhalla and we will be friends

Code: Select all

<ijon>well fuk
<ijon>guess I gotta suck dicks now

Code: Select all

(18:13:17)<Mayrine>i dont have to learnt anything about ACS

Synert
Forum Regular
Posts: 228
Joined: Mon Jun 04, 2012 12:54 pm
Contact:

RE: ACS: random() alternatives?

#12

Post by Synert » Tue Feb 19, 2013 11:01 pm

Hangman used to suffer from something related to random online- out of 500 words, it'd consistently use only ~6 of them every round.

Post Reply