// File: 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
subq $0x190, %rsp            # imm = 0x190
movl $0x0, -0x4(%rbp)
leaq -0x21(%rbp), %rdi
movq %rdi, -0x118(%rbp)
callq 0x1820
movq -0x118(%rbp), %rdx
leaq -0x20(%rbp), %rdi
movl $0x20, %esi
callq 0x1840
jmp 0x12d9
leaq -0x21(%rbp), %rdi
callq 0x18b0
leaq -0x40(%rbp), %rdi
callq 0x18d0
jmp 0x12ed
leaq -0x48(%rbp), %rdi
xorl %esi, %esi
movl $0x1f, %edx
callq 0x18f0
jmp 0x12ff
movq $0x0, -0x50(%rbp)
cmpq $0x64, -0x50(%rbp)
je 0x1376
leaq -0x48(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x1940
movl %eax, -0x11c(%rbp)
jmp 0x1323
movl -0x11c(%rbp), %eax
movl %eax, %eax
movl %eax, %esi
leaq -0x20(%rbp), %rdi
callq 0x1920
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0x1307
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x21(%rbp), %rdi
callq 0x18b0
jmp 0x180a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x1801
leaq -0x20(%rbp), %rdi
movq %rdi, -0x130(%rbp)
callq 0x19b0
movq -0x130(%rbp), %rdi
movq %rax, -0x68(%rbp)
callq 0x19e0
movq %rax, -0x70(%rbp)
movq -0x68(%rbp), %rdi
movq -0x70(%rbp), %rsi
callq 0x1970
movq %rax, -0x128(%rbp)
jmp 0x13b0
movq -0x128(%rbp), %rax
movq %rax, -0x60(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x1a10
movl (%rax), %eax
movl %eax, -0x54(%rbp)
movl -0x54(%rbp), %eax
movl %eax, -0x74(%rbp)
cmpl $0x0, -0x74(%rbp)
je 0x1480
movq $0x0, -0x80(%rbp)
movq -0x80(%rbp), %rax
movq %rax, -0x138(%rbp)
leaq -0x20(%rbp), %rdi
callq 0x1a30
movq %rax, %rcx
movq -0x138(%rbp), %rax
cmpq %rcx, %rax
je 0x145b
movq -0x80(%rbp), %rsi
leaq -0x20(%rbp), %rdi
callq 0x1920
movl (%rax), %eax
movl -0x74(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jle 0x1434
movq 0x4bb4(%rip), %rdi      # 0x5fd8
leaq 0x1c35(%rip), %rsi      # 0x3060
callq 0x10f0
jmp 0x1432
jmp 0x144b
movq 0x4b9d(%rip), %rdi      # 0x5fd8
leaq 0x1c21(%rip), %rsi      # 0x3063
callq 0x10f0
jmp 0x1449
jmp 0x144b
jmp 0x144d
movq -0x80(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x80(%rbp)
jmp 0x13e1
movq 0x4b76(%rip), %rdi      # 0x5fd8
movq 0x4b5f(%rip), %rsi      # 0x5fc8
callq 0x1120
jmp 0x1470
jmp 0x1472
movl -0x74(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x74(%rbp)
jmp 0x13cf
leaq -0x99(%rbp), %rdi
movq %rdi, -0x140(%rbp)
callq 0x1820
movq -0x140(%rbp), %rdx
leaq -0x98(%rbp), %rdi
movl $0x20, %esi
callq 0x1840
jmp 0x14ad
leaq -0x99(%rbp), %rdi
callq 0x18b0
leaq -0xa8(%rbp), %rdi
callq 0x18d0
jmp 0x14c7
leaq -0xc8(%rbp), %rdi
movsd 0x1b32(%rip), %xmm0     # 0x3008
movsd 0x1b32(%rip), %xmm1     # 0x3010
callq 0x1a50
jmp 0x14e5
movq $0x0, -0xd0(%rbp)
cmpq $0x64, -0xd0(%rbp)
je 0x1610
leaq -0xc8(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x1aa0
movsd %xmm0, -0x148(%rbp)
jmp 0x1518
movsd -0x148(%rbp), %xmm0
callq 0x1030
movq %rax, -0xd8(%rbp)
movq -0xd8(%rbp), %rax
movq %rax, -0x150(%rbp)
leaq -0x20(%rbp), %rdi
callq 0x1a30
movq %rax, %rcx
movq -0x150(%rbp), %rax
cmpq %rcx, %rax
jae 0x15a8
movq -0xd8(%rbp), %rsi
leaq -0x20(%rbp), %rdi
callq 0x1920
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
jmp 0x15f7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x99(%rbp), %rdi
callq 0x18b0
jmp 0x1801
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x1b30
jmp 0x1801
movq 0x4a29(%rip), %rdi      # 0x5fd8
leaq 0x1ab0(%rip), %rsi      # 0x3066
callq 0x10f0
movq %rax, -0x158(%rbp)
jmp 0x15c4
movq -0x158(%rbp), %rdi
movq -0xd8(%rbp), %rsi
callq 0x1040
movq %rax, -0x160(%rbp)
jmp 0x15e0
movq -0x160(%rbp), %rdi
leaq 0x1a76(%rip), %rsi      # 0x3064
callq 0x10f0
jmp 0x15f5
jmp 0x15f7
jmp 0x15f9
movq -0xd0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xd0(%rbp)
jmp 0x14f0
movq 0x49c1(%rip), %rdi      # 0x5fd8
movq 0x49aa(%rip), %rsi      # 0x5fc8
callq 0x1120
jmp 0x1625
leaq -0x20(%rbp), %rdi
movq %rdi, -0x170(%rbp)
callq 0x19b0
movq -0x170(%rbp), %rdi
movq %rax, -0xe0(%rbp)
callq 0x19e0
movq %rax, -0xe8(%rbp)
movq -0xe0(%rbp), %rdi
movq -0xe8(%rbp), %rsi
xorl %edx, %edx
callq 0x1ad0
movl %eax, -0x164(%rbp)
jmp 0x166c
movl -0x164(%rbp), %esi
movq 0x495f(%rip), %rdi      # 0x5fd8
callq 0x1140
movq %rax, -0x178(%rbp)
jmp 0x1687
movq -0x178(%rbp), %rdi
movq 0x4933(%rip), %rsi      # 0x5fc8
callq 0x1120
jmp 0x169c
leaq -0x20(%rbp), %rdi
movq %rdi, -0x188(%rbp)
callq 0x19b0
movq -0x188(%rbp), %rdi
movq %rax, -0xf8(%rbp)
callq 0x19e0
movq %rax, -0x100(%rbp)
movq -0xf8(%rbp), %rdi
movq -0x100(%rbp), %rsi
callq 0x1970
movq %rax, -0x180(%rbp)
jmp 0x16e2
movq -0x180(%rbp), %rax
movq %rax, -0xf0(%rbp)
leaq -0xf0(%rbp), %rdi
callq 0x1a10
movl (%rax), %eax
movl %eax, -0x54(%rbp)
movl -0x54(%rbp), %eax
movl %eax, -0x104(%rbp)
cmpl $0x0, -0x104(%rbp)
je 0x17d9
movq $0x0, -0x110(%rbp)
movq -0x110(%rbp), %rax
movq %rax, -0x190(%rbp)
leaq -0x20(%rbp), %rdi
callq 0x1a30
movq %rax, %rcx
movq -0x190(%rbp), %rax
cmpq %rcx, %rax
je 0x17ae
movq -0x110(%rbp), %rsi
leaq -0x20(%rbp), %rdi
callq 0x1920
movl (%rax), %eax
movl -0x104(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jle 0x177e
movq 0x486a(%rip), %rdi      # 0x5fd8
leaq 0x18eb(%rip), %rsi      # 0x3060
callq 0x10f0
jmp 0x177c
jmp 0x1795
movq 0x4853(%rip), %rdi      # 0x5fd8
leaq 0x18d7(%rip), %rsi      # 0x3063
callq 0x10f0
jmp 0x1793
jmp 0x1795
jmp 0x1797
movq -0x110(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x110(%rbp)
jmp 0x1722
movq 0x4823(%rip), %rdi      # 0x5fd8
movq 0x480c(%rip), %rsi      # 0x5fc8
callq 0x1120
jmp 0x17c3
jmp 0x17c5
movl -0x104(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x104(%rbp)
jmp 0x170a
movl $0x0, -0x4(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x1b30
leaq -0x20(%rbp), %rdi
callq 0x1b30
movl -0x4(%rbp), %eax
addq $0x190, %rsp            # imm = 0x190
popq %rbp
retq
leaq -0x20(%rbp), %rdi
callq 0x1b30
movq -0x30(%rbp), %rdi
callq 0x1150
nopw %cs:(%rax,%rax)
nopl (%rax)