// File: /workspace/github_cpp_makefile_star2_O1/iZhangHui[P]CppPrimer/CH17_SpecializedLibraryFacilities/examples/rand1.cc
// Function: main
int main()
{
	default_random_engine e;  // generates random unsigned integers
	for (size_t i = 0; i < 10; ++i)
		// e() "calls" the object to produce the next random number
		cout << e() << " ";
	cout << endl;

	// uniformly distributed from 0 to 9 inclusive
	uniform_int_distribution<unsigned> u(0,9);
	default_random_engine e2;  
	for (size_t i = 0; i < 10; ++i)
		// u uses e as a source of numbers
		// each call returns a uniformly distributed value 
		// in the specified range
    	cout << u(e2) << " ";
	cout << endl;

	default_random_engine e3;  
	// generates normally distributed doubles 
	// with mean 100, standard deviation 15
	normal_distribution<> n(100,15);  
	for (size_t i = 0; i < 10; ++i)
    	cout << n(e3) << " ";
	cout << endl;

	// bad, but common way to generate random numbers in a given range
	for (size_t i = 0; i < 10; ++i)
		// r will be a between 0 and 9, but randomness is compromised
		cout << rand()%10 << " ";
	cout << endl;

	default_random_engine e4;
	// uniformly distributed from 0 to 9 inclusive
	uniform_int_distribution<unsigned> u2(0,9);
	for (size_t i = 0; i < 10; ++i)
    	cout << u2(e4) << " ";
	cout << endl;

	// seeding the engine causes it to generate different numbers 
	// on different executions
	default_random_engine e5(time(0));  
	for (size_t i = 0; i < 10; ++i)
    	cout << u2(e5) << " ";
	cout << endl;

    // assuming shorts have 16 bits
    uniform_int_distribution<short> us1;     // values from 0 to 32767
    uniform_int_distribution<short> us2(42); // values from 42 to 32767
    cout << "min: " << us1.min() << " max: " << us1.max() << endl;
    cout << "min: " << us2.min() << " max: " << us2.max() << endl;

    default_random_engine e6;
    cout << "min: " << e6.min() << " max: " << e6.max() << endl;

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movl $0x1, %r15d
movl $0xa, %r12d
movabsq $0x200000005, %r13      # imm = 0x200000005
movq 0x2d3e(%rip), %rbx      # 0x3fd8
leaq 0xdc3(%rip), %r14       # 0x2064
imulq $0x41a7, %r15, %rcx     # imm = 0x41A7
movq %rcx, %rax
mulq %r13
movq %rcx, %r15
subq %rdx, %r15
shrq %r15
addq %rdx, %r15
shrq $0x1e, %r15
movq %r15, %rax
shlq $0x1f, %rax
subq %rax, %r15
addq %rcx, %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0x1060
movl $0x1, %edx
movq %rax, %rdi
movq %r14, %rsi
callq 0x10f0
decq %r12
jne 0x12a1
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x10e0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1070
movabsq $0x900000000, %rax      # imm = 0x900000000
leaq -0x58(%rbp), %r14
movq %rax, (%r14)
leaq -0x50(%rbp), %r15
movq $0x1, (%r15)
movl $0xa, %r13d
leaq 0xd29(%rip), %r12       # 0x2064
movq %r14, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x1710
movl %eax, %esi
movq %rbx, %rdi
callq 0x1060
movl $0x1, %edx
movq %rax, %rdi
movq %r12, %rsi
callq 0x10f0
decq %r13
jne 0x133b
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x10e0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1070
leaq -0x48(%rbp), %r14
movq $0x1, (%r14)
movabsq $0x4059000000000000, %rax # imm = 0x4059000000000000
leaq -0x78(%rbp), %r15
movq %rax, (%r15)
movabsq $0x402e000000000000, %rax # imm = 0x402E000000000000
movq %rax, 0x8(%r15)
movq $0x0, 0x10(%r15)
movb $0x0, 0x18(%r15)
movl $0xa, %r13d
leaq 0xc91(%rip), %r12       # 0x2064
movq %r15, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x1890
movq %rbx, %rdi
callq 0x1110
movl $0x1, %edx
movq %rax, %rdi
movq %r12, %rsi
callq 0x10f0
decq %r13
jne 0x13d3
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x10e0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1070
movl $0xa, %r15d
leaq 0xc32(%rip), %r14       # 0x2064
callq 0x1040
movslq %eax, %rsi
imulq $0x66666667, %rsi, %rax # imm = 0x66666667
movq %rax, %rcx
shrq $0x3f, %rcx
sarq $0x22, %rax
addl %ecx, %eax
addl %eax, %eax
leal (%rax,%rax,4), %eax
subl %eax, %esi
movq %rbx, %rdi
callq 0x1120
movl $0x1, %edx
movq %rax, %rdi
movq %r14, %rsi
callq 0x10f0
decq %r15
jne 0x1432
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x10e0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1070
leaq -0x40(%rbp), %r14
movq $0x1, (%r14)
leaq -0x30(%rbp), %r15
movabsq $0x900000000, %rax      # imm = 0x900000000
movq %rax, (%r15)
movl $0xa, %r13d
leaq 0xba2(%rip), %r12       # 0x2064
movq %r15, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x1710
movl %eax, %esi
movq %rbx, %rdi
callq 0x1060
movl $0x1, %edx
movq %rax, %rdi
movq %r12, %rsi
callq 0x10f0
decq %r13
jne 0x14c2
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x10e0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1070
xorl %edi, %edi
callq 0x10d0
movq %rax, %rcx
movabsq $0x200000005, %rdx      # imm = 0x200000005
mulq %rdx
movq %rcx, %rax
subq %rdx, %rax
shrq %rax
addq %rdx, %rax
shrq $0x1e, %rax
movq %rax, %rdx
shlq $0x1f, %rdx
subq %rdx, %rax
leaq (%rcx,%rax), %rdx
cmpq $0x1, %rdx
adcq %rcx, %rax
leaq -0x38(%rbp), %r14
movq %rax, (%r14)
movl $0xa, %r13d
leaq -0x30(%rbp), %r15
leaq 0xafa(%rip), %r12       # 0x2064
movq %r15, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x1710
movl %eax, %esi
movq %rbx, %rdi
callq 0x1060
movl $0x1, %edx
movq %rax, %rdi
movq %r12, %rsi
callq 0x10f0
decq %r13
jne 0x156a
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x10e0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1070
leaq 0xa9b(%rip), %r14       # 0x2060
movl $0x5, %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x10f0
movq %rbx, %rdi
xorl %esi, %esi
callq 0x10c0
movq %rax, %r12
leaq 0xa7d(%rip), %r15       # 0x2066
movl $0x6, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x10f0
movq %r12, %rdi
movl $0x7fff, %esi           # imm = 0x7FFF
callq 0x10c0
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x10e0
movsbl %al, %esi
movq %r12, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1070
movl $0x5, %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x10f0
movq %rbx, %rdi
movl $0x2a, %esi
callq 0x10c0
movq %rax, %r12
movl $0x6, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x10f0
movq %r12, %rdi
movl $0x7fff, %esi           # imm = 0x7FFF
callq 0x10c0
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x10e0
movsbl %al, %esi
movq %r12, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1070
movl $0x5, %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x10f0
movl $0x1, %esi
movq %rbx, %rdi
callq 0x1060
movq %rax, %rbx
movl $0x6, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x10f0
movl $0x7ffffffe, %esi       # imm = 0x7FFFFFFE
movq %rbx, %rdi
callq 0x1060
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x10e0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1070
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop