ent_bonemove & _bonerotate affect random sequence?

Posted By: Error014

ent_bonemove & _bonerotate affect random sequence? - 10/10/17 22:52

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!
Posted By: jcl

Re: ent_bonemove & _bonerotate affect random sequence? - 10/12/17 09:00

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.
© 2024 lite-C Forums