Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, Imhotep), 567 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
ent_bonemove & _bonerotate affect random sequence? #468579
10/10/17 22:52
10/10/17 22:52
Joined: Jul 2002
Posts: 3,208
Germany
Error014 Offline OP
Expert
Error014  Offline OP
Expert

Joined: Jul 2002
Posts: 3,208
Germany
Hello!

I am using "random_seed" with defined seeds, to ensure a very particular random sequence.
But as it turns out, there are instructions other than "random" that affect the sequence. The following piece of code illustrates that. You'll need a model with a bone, here, the model is called "NPCGen_09.mdl", and the bone "head".

Code:
function main() {
	char i;
	ENTITY* test;
	
	level_load(NULL);
	wait(1);
	wait(1);
	wait(1);
	test = ent_create("NPCGen_09.mdl",nullvector,NULL);
	
	diag("n --- n");	
	random_seed(1);
	for(i=0;i<10;i++) diag_var("%6.3f ",random(1000));

	diag("n --- n");	
	
	random_seed(1);
	wait(-0.5); //<- does not affect the sequence
	for(i=0;i<10;i++) diag_var("%6.3f ",random(1000));

	diag("n --- n");	
	
	random_seed(1);
	//ent_bonerotate(test,"head",vector(0,0,1)); // <- affects the sequence -> shifts by one
	ent_bonemove(test,"head",vector(0,0,1)); // <- affects the sequence -> shifts by one
	//VECTOR t; t.x=0;t.y=0;t.z=1;ent_bonerotate(test,"head",t); //this also affects the sequence (so it's not "vector")
	for(i=0;i<10;i++) diag_var("%6.3f ",random(1000));
	
	sys_exit("");
	
}



After not much interesting stuff for initialization, "random_seed(1);" sets a sequence, of which the first 10 elements as found by random(1000) are output in the acklog:

Code:
123.260 903.473 52.917 600.677 70.313 519.378 507.935 306.091 807.098 556.549



Next up, to ensure that it's not just a general timing issue, I re-initialize the sequence, wait half a second, and output the first 10 elements. No change there.

But! Then we re-initialize the sequence, and call one of the ent_bone*-instructions. The 10 elements output are now shifted by one (we skip the "123.260"):

Code:
903.473 52.917 600.677 70.313 519.378 507.935 306.091 807.098 556.549 234.009





Why do these instruction affect the random sequence? Which other instructions do? Additionally, more information on the exact generation of the random sequence would be appreciated.

Thanks!

Last edited by Error014; 10/10/17 22:53.

Perhaps this post will get me points for originality at least.

Check out Dungeon Deities! It's amazing and will make you happy, successful and almost certainly more attractive! It might be true!
Re: ent_bonemove & _bonerotate affect random sequence? [Re: Error014] #468649
10/12/17 09:00
10/12/17 09:00
Joined: Jul 2000
Posts: 27,977
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,977
Frankfurt
The random sequence is indeed affected by functions that internally use random numbers for some purpose. I don't have a list, but do not rely on an unchanged order of the random sequence when the script changes. If you need a fixed order, you could use a script based random generator - I believe there can be some found on the Internet.


Moderated by  jcl, Nems, Spirit, Tobias 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1