// File: /workspace/github_cpp_makefile_star2_O2/iZhangHui[P]CppPrimer/CH17_SpecializedLibraryFacilities/examples/rand2.cc
// Function: main
int main()
{
	vector<int> vals(32);     // preallocate so each element is 0 
	default_random_engine e;  // generates numbers
	uniform_int_distribution<unsigned> u(0,31); // inclusive range 
	for (size_t i = 0; i != 100; ++i)
		++vals[u(e)];         // count how often each number appears
	int m = *max_element(vals.begin(), vals.end());
	for (int i = m; i != 0; --i) {
		for (size_t j = 0; j != vals.size(); ++j)
			if (vals[j] > i-1) cout << "* ";
			else               cout << "  ";
		cout << endl;
	}

	vector<int> vals2(32);     // preallocate so each element 0 value
	default_random_engine e2;  // restart the sequence
	normal_distribution<> n(15,5); // mean 15, standard deviation 5
	for (size_t i = 0; i != 100; ++i) {
		size_t v = lround(n(e));
		if (v < vals.size())
			++vals[v];         // count how often each number appears
		else
			cout << "discarding: " << v << " ";
	}
	cout << endl;

	cout << std::accumulate(vals.begin(), vals.end(), 0) << endl;
	m = *max_element(vals.begin(), vals.end());
	for (int i = m; i != 0; --i) {
		for (size_t j = 0; j != vals.size(); ++j)
			if (vals[j] > i-1) cout << "* ";
			else               cout << "  ";
		cout << endl;
	}

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
leaq -0x48(%rbp), %rdi
pushq $0x20
popq %rsi
leaq -0x90(%rbp), %rdx
callq 0x1514
leaq -0x50(%rbp), %rbx
movq $0x1, (%rbx)
movabsq $0x1f00000000, %rax     # imm = 0x1F00000000
leaq -0x70(%rbp), %r14
movq %rax, (%r14)
pushq $0x64
popq %r15
subq $0x1, %r15
jb 0x12fc
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1566
movl %eax, %eax
movq -0x48(%rbp), %rcx
incl (%rcx,%rax,4)
jmp 0x12e0
movq -0x48(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x1581
movl (%rax), %r13d
movq 0x2cc5(%rip), %rbx      # 0x3fd8
leaq 0xd49(%rip), %r14       # 0x2063
leaq 0xd3f(%rip), %r15       # 0x2060
movl %r13d, %eax
subl $0x1, %eax
jb 0x136c
movl %eax, -0x2c(%rbp)
xorl %r12d, %r12d
movq -0x48(%rbp), %rax
movq -0x40(%rbp), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
cmpq %rcx, %r12
je 0x135c
movq %r14, %rsi
cmpl %r13d, (%rax,%r12,4)
jl 0x134f
movq %r15, %rsi
movq %rbx, %rdi
callq 0x1100
incq %r12
jmp 0x132f
movq %rbx, %rdi
callq 0x1070
movl -0x2c(%rbp), %eax
movl %eax, %r13d
jmp 0x1324
leaq -0x68(%rbp), %rdi
pushq $0x20
popq %rsi
leaq -0x90(%rbp), %rdx
callq 0x1514
movabsq $0x402e000000000000, %rax # imm = 0x402E000000000000
leaq -0x90(%rbp), %rbx
movq %rax, (%rbx)
movabsq $0x4014000000000000, %rax # imm = 0x4014000000000000
movq %rax, 0x8(%rbx)
andq $0x0, 0x10(%rbx)
movb $0x0, 0x18(%rbx)
pushq $0x64
popq %r12
leaq -0x50(%rbp), %r14
leaq 0xcab(%rip), %r13       # 0x2064
subq $0x1, %r12
jb 0x1417
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1574
callq 0x1030
movq %rax, %r15
movq -0x48(%rbp), %rax
movq -0x40(%rbp), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
cmpq %rcx, %r15
jae 0x13ec
incl (%rax,%r15,4)
jmp 0x13b9
movq 0x2be5(%rip), %rdi      # 0x3fd8
leaq 0xc6c(%rip), %rsi       # 0x2066
callq 0x1100
movq %rax, %rdi
movq %r15, %rsi
callq 0x10a0
movq %rax, %rdi
movq %r13, %rsi
callq 0x1100
jmp 0x13b9
movq 0x2bba(%rip), %rdi      # 0x3fd8
callq 0x1070
movq -0x48(%rbp), %rax
movq -0x40(%rbp), %rcx
xorl %esi, %esi
cmpq %rcx, %rax
je 0x143a
addl (%rax), %esi
addq $0x4, %rax
jmp 0x142d
movq 0x2b97(%rip), %rdi      # 0x3fd8
callq 0x1140
movq %rax, %rdi
callq 0x1070
movq -0x48(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x1581
movl (%rax), %r13d
movq 0x2b73(%rip), %rbx      # 0x3fd8
leaq 0xbf7(%rip), %r14       # 0x2063
leaq 0xbed(%rip), %r15       # 0x2060
movl %r13d, %eax
subl $0x1, %eax
jb 0x14be
movl %eax, -0x2c(%rbp)
xorl %r12d, %r12d
movq -0x48(%rbp), %rax
movq -0x40(%rbp), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
cmpq %rcx, %r12
je 0x14ae
movq %r14, %rsi
cmpl %r13d, (%rax,%r12,4)
jl 0x14a1
movq %r15, %rsi
movq %rbx, %rdi
callq 0x1100
incq %r12
jmp 0x1481
movq %rbx, %rdi
callq 0x1070
movl -0x2c(%rbp), %eax
movl %eax, %r13d
jmp 0x1476
leaq -0x68(%rbp), %rdi
callq 0x15e8
leaq -0x48(%rbp), %rdi
callq 0x15e8
xorl %eax, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x14f1
jmp 0x14ff
jmp 0x14ff
jmp 0x14f1
jmp 0x14f1
jmp 0x14ff
jmp 0x14ff
jmp 0x14f1
movq %rax, %rbx
leaq -0x68(%rbp), %rdi
callq 0x15e8
jmp 0x1502
movq %rax, %rbx
leaq -0x48(%rbp), %rdi
callq 0x15e8
movq %rbx, %rdi
callq 0x1150
nop