// File: /workspace/github_cpp_makefile_star2_O2/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
pushq $0x1
popq %rbx
pushq $0xa
popq %r12
movl $0x7fffffff, %r13d      # imm = 0x7FFFFFFF
movq 0x2d67(%rip), %r14      # 0x3fd8
leaq 0xdec(%rip), %r15       # 0x2064
subq $0x1, %r12
jb 0x12a5
imulq $0x41a7, %rbx, %rax     # imm = 0x41A7
xorl %edx, %edx
divq %r13
movq %rdx, %rbx
movq %r14, %rdi
movq %rdx, %rsi
callq 0x1060
movq %rax, %rdi
movq %r15, %rsi
callq 0x10d0
jmp 0x1278
movq 0x2d2c(%rip), %rbx      # 0x3fd8
movq %rbx, %rdi
callq 0x1040
movabsq $0x900000000, %rax      # imm = 0x900000000
leaq -0x58(%rbp), %r14
movq %rax, (%r14)
leaq -0x50(%rbp), %r15
movq $0x1, (%r15)
pushq $0xa
popq %r13
leaq 0xd89(%rip), %r12       # 0x2064
subq $0x1, %r13
jb 0x1303
movq %r14, %rdi
movq %r15, %rsi
callq 0x154e
movl %eax, %esi
movq %rbx, %rdi
callq 0x1060
movq %rax, %rdi
movq %r12, %rsi
callq 0x10d0
jmp 0x12db
movq 0x2cce(%rip), %rbx      # 0x3fd8
movq %rbx, %rdi
callq 0x1040
leaq -0x48(%rbp), %r14
movabsq $0x4059000000000000, %rax # imm = 0x4059000000000000
leaq -0x78(%rbp), %r15
movq %rax, (%r15)
movabsq $0x402e000000000000, %rax # imm = 0x402E000000000000
movq %rax, 0x8(%r15)
andq $0x0, 0x10(%r15)
movq $0x1, (%r14)
movb $0x0, 0x18(%r15)
pushq $0xa
popq %r13
leaq 0xd13(%rip), %r12       # 0x2064
subq $0x1, %r13
jb 0x1377
movq %r15, %rdi
movq %r14, %rsi
callq 0x155c
movq %rbx, %rdi
callq 0x10f0
movq %rax, %rdi
movq %r12, %rsi
callq 0x10d0
jmp 0x1351
movq 0x2c5a(%rip), %rbx      # 0x3fd8
movq %rbx, %rdi
callq 0x1040
pushq $0xa
popq %r15
pushq $0xa
popq %r12
leaq 0xccf(%rip), %r14       # 0x2064
subq $0x1, %r15
jb 0x13bb
callq 0x1030
cltd
idivl %r12d
movq %rbx, %rdi
movl %edx, %esi
callq 0x1100
movq %rax, %rdi
movq %r14, %rsi
callq 0x10d0
jmp 0x1395
movq 0x2c16(%rip), %rbx      # 0x3fd8
movq %rbx, %rdi
callq 0x1040
leaq -0x40(%rbp), %r14
movq $0x1, (%r14)
leaq -0x30(%rbp), %r15
movabsq $0x900000000, %rax      # imm = 0x900000000
movq %rax, (%r15)
pushq $0xa
popq %r13
leaq 0xc73(%rip), %r12       # 0x2064
subq $0x1, %r13
jb 0x1419
movq %r15, %rdi
movq %r14, %rsi
callq 0x154e
movl %eax, %esi
movq %rbx, %rdi
callq 0x1060
movq %rax, %rdi
movq %r12, %rsi
callq 0x10d0
jmp 0x13f1
movq 0x2bb8(%rip), %rbx      # 0x3fd8
movq %rbx, %rdi
callq 0x1040
xorl %edi, %edi
callq 0x10c0
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
xorl %edx, %edx
divq %rcx
cmpq $0x1, %rdx
adcq $0x0, %rdx
leaq -0x38(%rbp), %r14
movq %rdx, (%r14)
pushq $0xa
popq %r13
leaq -0x30(%rbp), %r15
leaq 0xc0d(%rip), %r12       # 0x2064
subq $0x1, %r13
jb 0x147f
movq %r15, %rdi
movq %r14, %rsi
callq 0x154e
movl %eax, %esi
movq %rbx, %rdi
callq 0x1060
movq %rax, %rdi
movq %r12, %rsi
callq 0x10d0
jmp 0x1457
movq 0x2b52(%rip), %rbx      # 0x3fd8
movq %rbx, %rdi
callq 0x1040
leaq 0xbcb(%rip), %r14       # 0x2060
movq %rbx, %rdi
movq %r14, %rsi
callq 0x10d0
movq %rax, %rdi
xorl %esi, %esi
callq 0x10b0
leaq 0xbb5(%rip), %r15       # 0x2066
movq %rax, %rdi
movq %r15, %rsi
callq 0x10d0
movq %rax, %rdi
movl $0x7fff, %esi           # imm = 0x7FFF
callq 0x10b0
movq %rax, %rdi
callq 0x1040
movq %rbx, %rdi
movq %r14, %rsi
callq 0x10d0
pushq $0x2a
popq %rsi
movq %rax, %rdi
callq 0x10b0
movq %rax, %rdi
movq %r15, %rsi
callq 0x10d0
movq %rax, %rdi
movl $0x7fff, %esi           # imm = 0x7FFF
callq 0x10b0
movq %rax, %rdi
callq 0x1040
movq %rbx, %rdi
movq %r14, %rsi
callq 0x10d0
pushq $0x1
popq %rsi
movq %rax, %rdi
callq 0x1060
movq %rax, %rdi
movq %r15, %rsi
callq 0x10d0
movl $0x7ffffffe, %esi       # imm = 0x7FFFFFFE
movq %rax, %rdi
callq 0x1060
movq %rax, %rdi
callq 0x1040
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq