// File: /workspace/github_cpp_makefile_star2_O2/richardposner[P]BioNetFit2/src/code/Particle.cpp
// Function: Particle::generateParams()
void Particle::generateParams() {
	// for a possibly better way to generate numbers
	// freeParams_ is a map with the first element being a parameter name, and the second element being a pointer to a FreeParam object
	//razi: in this new version we have vectors of these maps. Each vector element belongs to one of the parallel models indexed by mid

//cout<<"Particle::generateParams XXX-1"<<endl;
//	for (unsigned int mid = 0; mid < models.size(); ++mid)
//	if (models.at(mid))
//	for (map<string,FreeParam*>::iterator i = models.at(mid)->freeParams_.begin(); i != models.at(mid)->freeParams_.end(); ++i) {
	if (models.at(0))
	for (map<string,FreeParam*>::iterator i = models.at(0)->freeParams_.begin(); i != models.at(0)->freeParams_.end(); ++i) {


		//vector<string> values;

		// Split our generation method/range into parts.
		//split(i->second, values);

		// Make sure our array contains the generation method
		/*if (values[0].empty()){
			string errMsg = "Problem parsing initial parameter generator for param: " + i->first + ".";
			outputError (errMsg);
		}*/

		// Store the free parameter name that we're currently generating
		string paramName;
		paramName = i->first;

		// Store the generation method
		//string genType = values[0];
		string genType = i->second->getGenerationMethod();

		// Generate a number on a linear scale
		if (genType == "random_var"){
			// Store our min and max values
			double min = i->second->getGenMin();
			double max = i->second->getGenMax();

			std::random_device rd;
			std::mt19937 mt(rd());
			std::uniform_real_distribution<double> dist(min, max);
			
			float myrand = dist(mt);

			pair<string,double> paramPair = make_pair(paramName, myrand);

//cout<<"Particle::generateParams XXX-2"<<endl;

			//code for forcing the subparticles to have the same values
			for (unsigned int mid = 0; mid < models.size(); mid++){
				if (models.at(mid)){
					setParam(paramPair, mid);

				}
			}
//cout<<"Particle::generateParams XXX-3"<<endl;

		}
		else if (genType == "loguniform_var") {

			// Store our min and max values
			double min = i->second->getGenMin();
			double max = i->second->getGenMax();

			//cout << "generating with " << min << ":" << max << endl;

			// Generate a random double between 0 and rand_max
			double myrand = static_cast <double> (rand()) / static_cast<double> (RAND_MAX);
			//cout << id_ << " rand is " << myrand << endl;

			//
			double exp = log10(min) + myrand * (log10(max) - log10(min) );
			//cout << id_ << " base is " << exp << endl;
			//cout << id_ << " final " << pow(10, exp) << endl << endl;

			pair<string,double> paramPair = make_pair(paramName, pow(10, exp));

//cout<<"Particle::generateParams XXX-4"<<endl; mypause();
			//	unsigned int subParID = parParticle->calcsubParID(mid);

			//code for forcing the subparticles to have the same values
			for (unsigned int mid = 0; mid < models.size(); mid++){
				if (models.at(mid)){
					setParam(paramPair, mid);
				}
			}
			//setParam(paramPair, mid);
//cout<<"Particle::generateParams XXX-5"<<endl; mypause();

		}
//cout<<"Particle::generateParams XXX-6"<<endl; mypause()
		//TODO: Add the rest of the init parm generation options
	}
//cout<<"Particle::generateParams XXX-7"<<endl; mypause();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2838, %rsp           # imm = 0x2838
movq %rdi, %rbx
leaq 0x78(%rdi), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0x3374c
cmpq $0x0, (%rax)
je 0x50fc4
movq %r14, %rdi
xorl %esi, %esi
callq 0x3374c
movq (%rax), %rax
movq 0x48(%rax), %r12
leaq 0xd8(%rsp), %r13
leaq 0xb0(%rsp), %rbp
movq %r14, %rdi
xorl %esi, %esi
callq 0x3374c
movq (%rax), %rax
addq $0x38, %rax
cmpq %rax, %r12
je 0x50fc4
leaq 0x30(%rsp), %rax
movq %rax, 0x20(%rsp)
andq $0x0, 0x28(%rsp)
movb $0x0, 0x30(%rsp)
leaq 0x20(%r12), %rsi
leaq 0x20(%rsp), %rdi
callq 0x28570
movq 0x40(%r12), %rsi
addq $0x20, %rsi
leaq 0x90(%rsp), %r15
movq %r15, %rdi
callq 0x28dd0
movq %r15, %rdi
leaq 0x7eca1(%rip), %rsi     # 0xcfa19
callq 0x3357b
testb %al, %al
je 0x50e66
movq 0x40(%r12), %rax
cvtps2pd 0x48(%rax), %xmm0
movaps %xmm0, (%rsp)
leaq 0x128(%rsp), %r15
movq %r15, %rdi
callq 0x59ec0
movq %r15, %rdi
callq 0x28df0
leaq 0x14b0(%rsp), %r15
movl %eax, %esi
movq %r15, %rdi
callq 0x5c600
movaps (%rsp), %xmm0
movaps %xmm0, 0x50(%rsp)
leaq 0x50(%rsp), %rdi
movq %r15, %rsi
callq 0x59f16
movsd %xmm0, (%rsp)
leaq 0x100(%rsp), %r15
movq %r15, %rdi
leaq 0x20(%rsp), %rsi
callq 0x28dd0
cvtsd2ss (%rsp), %xmm0
movss %xmm0, 0x120(%rsp)
leaq 0x68(%rsp), %rdi
movq %r15, %rsi
callq 0x59f1e
movq %r15, %rdi
callq 0x295a0
xorl %r15d, %r15d
movl %r15d, %r15d
movq 0x80(%rbx), %rax
subq 0x78(%rbx), %rax
sarq $0x3, %rax
cmpq %r15, %rax
jbe 0x50f77
movq %r14, %rdi
movq %r15, %rsi
callq 0x3374c
cmpq $0x0, (%rax)
je 0x50e61
movq %r13, %rdi
leaq 0x68(%rsp), %rsi
callq 0x59f40
movq %rbx, %rdi
movq %r13, %rsi
movl %r15d, %edx
callq 0x5105c
movq %r13, %rdi
callq 0x295a0
incl %r15d
jmp 0x50e12
movq %r15, %rdi
leaq 0x7ebb4(%rip), %rsi     # 0xcfa24
callq 0x3357b
testb %al, %al
je 0x50f9d
movq 0x40(%r12), %rax
cvtss2sd 0x48(%rax), %xmm0
movsd %xmm0, (%rsp)
cvtss2sd 0x4c(%rax), %xmm0
movsd %xmm0, 0x18(%rsp)
callq 0x28280
cvtsi2sd %eax, %xmm0
divsd 0x85358(%rip), %xmm0    # 0xd6200
movsd %xmm0, 0x48(%rsp)
movsd (%rsp), %xmm0
callq 0x284f0
movsd %xmm0, 0x40(%rsp)
movsd 0x18(%rsp), %xmm0
callq 0x284f0
movsd %xmm0, 0x18(%rsp)
movsd (%rsp), %xmm0
callq 0x284f0
movsd 0x18(%rsp), %xmm1
subsd %xmm0, %xmm1
mulsd 0x48(%rsp), %xmm1
addsd 0x40(%rsp), %xmm1
movsd 0x85311(%rip), %xmm0    # 0xd6208
callq 0x292b0
movsd %xmm0, (%rsp)
leaq 0x128(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x28dd0
movsd (%rsp), %xmm0
movsd %xmm0, 0x148(%rsp)
xorl %r15d, %r15d
movl %r15d, %r15d
movq 0x80(%rbx), %rax
subq 0x78(%rbx), %rax
sarq $0x3, %rax
cmpq %r15, %rax
jbe 0x50f90
movq %r14, %rdi
movq %r15, %rsi
callq 0x3374c
cmpq $0x0, (%rax)
je 0x50f72
movq %rbp, %rdi
leaq 0x128(%rsp), %rsi
callq 0x59f40
movq %rbx, %rdi
movq %rbp, %rsi
movl %r15d, %edx
callq 0x5105c
movq %rbp, %rdi
callq 0x295a0
incl %r15d
jmp 0x50f24
leaq 0x68(%rsp), %rdi
callq 0x295a0
leaq 0x128(%rsp), %rdi
callq 0x59f62
jmp 0x50f9d
leaq 0x128(%rsp), %rdi
callq 0x295a0
leaq 0x90(%rsp), %rdi
callq 0x295a0
leaq 0x20(%rsp), %rdi
callq 0x295a0
movq %r12, %rdi
callq 0x28700
movq %rax, %r12
jmp 0x50d17
addq $0x2838, %rsp           # imm = 0x2838
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x50fda
jmp 0x50fe8
movq %rax, %rbx
jmp 0x5103d
jmp 0x50fe8
jmp 0x50fe3
movq %rax, %rbx
jmp 0x5104a
movq %rax, %rbx
jmp 0x51030
movq %rax, %rbx
leaq 0xb0(%rsp), %rdi
callq 0x295a0
jmp 0x51014
movq %rax, %rbx
leaq 0xd8(%rsp), %rdi
callq 0x295a0
jmp 0x51026
movq %rax, %rbx
leaq 0x128(%rsp), %rdi
callq 0x295a0
jmp 0x5103d
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
callq 0x295a0
leaq 0x128(%rsp), %rdi
callq 0x59f62
leaq 0x90(%rsp), %rdi
callq 0x295a0
leaq 0x20(%rsp), %rdi
callq 0x295a0
movq %rbx, %rdi
callq 0x292f0