// File: 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
movq %rsp, %rbp
subq $0x2920, %rsp           # imm = 0x2920
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x28a8(%rbp)
addq $0x78, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x45190
cmpq $0x0, (%rax)
je 0xa3c55
movq -0x28a8(%rbp), %rdi
addq $0x78, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x45190
movq (%rax), %rdi
addq $0x30, %rdi
callq 0x44c70
movq %rax, -0x10(%rbp)
movq -0x28a8(%rbp), %rdi
addq $0x78, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x45190
movq (%rax), %rdi
addq $0x30, %rdi
callq 0x44cd0
movq %rax, -0x18(%rbp)
leaq -0x10(%rbp), %rdi
leaq -0x18(%rbp), %rsi
callq 0x44ca0
testb $0x1, %al
jne 0xa36cf
jmp 0xa3c53
leaq -0x38(%rbp), %rdi
movq %rdi, -0x28b0(%rbp)
callq 0x2f880
leaq -0x10(%rbp), %rdi
callq 0x44d00
movq -0x28b0(%rbp), %rdi
movq %rax, %rsi
callq 0x30fa0
jmp 0xa36f9
leaq -0x10(%rbp), %rdi
callq 0x44d00
movq 0x20(%rax), %rsi
leaq -0x68(%rbp), %rdi
callq 0xb26c0
jmp 0xa3711
leaq 0x130736(%rip), %rsi    # 0x1d3e4e
leaq -0x68(%rbp), %rdi
callq 0x44930
movb %al, -0x28b1(%rbp)
jmp 0xa3729
movb -0x28b1(%rbp), %al
testb $0x1, %al
jne 0xa3738
jmp 0xa39be
leaq -0x10(%rbp), %rdi
callq 0x44d00
movq 0x20(%rax), %rdi
callq 0xb26f0
movss %xmm0, -0x28b8(%rbp)
jmp 0xa3754
movss -0x28b8(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x70(%rbp)
leaq -0x10(%rbp), %rdi
callq 0x44d00
movq 0x20(%rax), %rdi
callq 0xb2710
movss %xmm0, -0x28bc(%rbp)
jmp 0xa3781
movss -0x28bc(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x78(%rbp)
leaq -0x1400(%rbp), %rdi
callq 0xb2730
jmp 0xa37a0
leaq -0x1400(%rbp), %rdi
callq 0xb27d0
movl %eax, -0x28c0(%rbp)
jmp 0xa37b4
movl -0x28c0(%rbp), %eax
movl %eax, %eax
movl %eax, %esi
leaq -0x2788(%rbp), %rdi
callq 0xb27f0
jmp 0xa37cc
movsd -0x70(%rbp), %xmm0
movsd -0x78(%rbp), %xmm1
leaq -0x2798(%rbp), %rdi
callq 0xb2820
jmp 0xa37e4
leaq -0x2798(%rbp), %rdi
leaq -0x2788(%rbp), %rsi
callq 0xb2850
movsd %xmm0, -0x28c8(%rbp)
jmp 0xa3801
movsd -0x28c8(%rbp), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x279c(%rbp)
leaq -0x27f0(%rbp), %rdi
leaq -0x38(%rbp), %rsi
leaq -0x279c(%rbp), %rdx
callq 0xb2880
jmp 0xa382e
leaq -0x27c8(%rbp), %rdi
leaq -0x27f0(%rbp), %rsi
callq 0xb28c0
jmp 0xa3843
leaq -0x27f0(%rbp), %rdi
callq 0xb2900
movl $0x0, -0x27f4(%rbp)
movq -0x28a8(%rbp), %rdi
movl -0x27f4(%rbp), %eax
movq %rax, -0x28d0(%rbp)
addq $0x78, %rdi
callq 0x45170
movq %rax, %rcx
movq -0x28d0(%rbp), %rax
cmpq %rcx, %rax
jae 0xa3984
movq -0x28a8(%rbp), %rdi
addq $0x78, %rdi
movl -0x27f4(%rbp), %eax
movl %eax, %esi
callq 0x45190
movq %rax, -0x28d8(%rbp)
jmp 0xa38aa
movq -0x28d8(%rbp), %rax
cmpq $0x0, (%rax)
je 0xa396e
leaq -0x2820(%rbp), %rdi
leaq -0x27c8(%rbp), %rsi
callq 0xb2920
jmp 0xa38d0
movq -0x28a8(%rbp), %rdi
movl -0x27f4(%rbp), %edx
leaq -0x2820(%rbp), %rsi
callq 0xa3c70
jmp 0xa38eb
leaq -0x2820(%rbp), %rdi
callq 0x8e7a0
jmp 0xa396e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0xa3c48
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0xa3c3f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0xa39ad
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x27f0(%rbp), %rdi
callq 0xb2900
jmp 0xa39ad
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0xa39a1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x2820(%rbp), %rdi
callq 0x8e7a0
jmp 0xa39a1
jmp 0xa3970
movl -0x27f4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x27f4(%rbp)
jmp 0xa3859
leaq -0x27c8(%rbp), %rdi
callq 0x8e7a0
leaq -0x1400(%rbp), %rdi
callq 0xb2960
jmp 0xa3c1f
leaq -0x27c8(%rbp), %rdi
callq 0x8e7a0
leaq -0x1400(%rbp), %rdi
callq 0xb2960
jmp 0xa3c3f
leaq 0x130494(%rip), %rsi    # 0x1d3e59
leaq -0x68(%rbp), %rdi
callq 0x44930
movb %al, -0x28d9(%rbp)
jmp 0xa39d6
movb -0x28d9(%rbp), %al
testb $0x1, %al
jne 0xa39e5
jmp 0xa3c1d
leaq -0x10(%rbp), %rdi
callq 0x44d00
movq 0x20(%rax), %rdi
callq 0xb26f0
movss %xmm0, -0x28e0(%rbp)
jmp 0xa3a01
movss -0x28e0(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x2828(%rbp)
leaq -0x10(%rbp), %rdi
callq 0x44d00
movq 0x20(%rax), %rdi
callq 0xb2710
movss %xmm0, -0x28e4(%rbp)
jmp 0xa3a31
movss -0x28e4(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x2830(%rbp)
callq 0x30b00
cvtsi2sd %eax, %xmm0
movsd 0x1370ca(%rip), %xmm1   # 0x1dab20
divsd %xmm1, %xmm0
movsd %xmm0, -0x2838(%rbp)
movsd -0x2828(%rbp), %xmm0
callq 0x2fd10
movsd %xmm0, -0x2900(%rbp)
movsd -0x2838(%rbp), %xmm0
movsd %xmm0, -0x28f8(%rbp)
movsd -0x2830(%rbp), %xmm0
callq 0x2fd10
movsd %xmm0, -0x2908(%rbp)
movsd -0x2828(%rbp), %xmm0
callq 0x2fd10
movsd -0x2908(%rbp), %xmm2
movsd -0x2900(%rbp), %xmm1
movaps %xmm0, %xmm3
movsd -0x28f8(%rbp), %xmm0
subsd %xmm3, %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x2840(%rbp)
movsd -0x2840(%rbp), %xmm0
movl $0xa, %edi
callq 0xb29d0
movsd %xmm0, -0x28f0(%rbp)
jmp 0xa3af4
movsd -0x28f0(%rbp), %xmm0
movsd %xmm0, -0x2870(%rbp)
leaq -0x2868(%rbp), %rdi
leaq -0x38(%rbp), %rsi
leaq -0x2870(%rbp), %rdx
callq 0xb2990
jmp 0xa3b1d
movl $0x0, -0x2874(%rbp)
movq -0x28a8(%rbp), %rdi
movl -0x2874(%rbp), %eax
movq %rax, -0x2910(%rbp)
addq $0x78, %rdi
callq 0x45170
movq %rax, %rcx
movq -0x2910(%rbp), %rax
cmpq %rcx, %rax
jae 0xa3c01
movq -0x28a8(%rbp), %rdi
addq $0x78, %rdi
movl -0x2874(%rbp), %eax
movl %eax, %esi
callq 0x45190
movq %rax, -0x2918(%rbp)
jmp 0xa3b78
movq -0x2918(%rbp), %rax
cmpq $0x0, (%rax)
je 0xa3beb
leaq -0x28a0(%rbp), %rdi
leaq -0x2868(%rbp), %rsi
callq 0xb2920
jmp 0xa3b9a
movq -0x28a8(%rbp), %rdi
movl -0x2874(%rbp), %edx
leaq -0x28a0(%rbp), %rsi
callq 0xa3c70
jmp 0xa3bb5
leaq -0x28a0(%rbp), %rdi
callq 0x8e7a0
jmp 0xa3beb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0xa3c0f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x28a0(%rbp), %rdi
callq 0x8e7a0
jmp 0xa3c0f
jmp 0xa3bed
movl -0x2874(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2874(%rbp)
jmp 0xa3b27
leaq -0x2868(%rbp), %rdi
callq 0x8e7a0
jmp 0xa3c1d
leaq -0x2868(%rbp), %rdi
callq 0x8e7a0
jmp 0xa3c3f
jmp 0xa3c1f
leaq -0x68(%rbp), %rdi
callq 0x311e8
leaq -0x38(%rbp), %rdi
callq 0x311e8
leaq -0x10(%rbp), %rdi
callq 0x44d20
jmp 0xa3695
leaq -0x68(%rbp), %rdi
callq 0x311e8
leaq -0x38(%rbp), %rdi
callq 0x311e8
jmp 0xa3c5e
jmp 0xa3c55
addq $0x2920, %rsp           # imm = 0x2920
popq %rbp
retq
movq -0x40(%rbp), %rdi
callq 0x30170
nopw (%rax,%rax)