Random number generation procedure:
- prepare the stochastic system: get yourself a coin and check it for usability;
- toss the coin;
- note the obtained coin position;
- go to stage 2 (if still needed, repeat as much times as needed);
- convert the noted coin position into a usable form.
- if a coin had an ideal uniformity and symmetry, it could be considered an ideal (metal) disc;
- a common coin has 2 distinctive sides, so the probability to see a specific side up (not taking the edge into account) is 1/2 = 0.5;
- a system with 2 stable states can give you a hint of a binary numeral system;
- the obvious lack of system's memory gives you an opportunity to generate as many random bits as you want;
- if you toss the coin n times, you can get a random number from 0 to (2n-1); e. g., for 8 flips, the max number is: 28 - 1 = 256 - 1 = 255.
- "heads" (obverse; usually shows the state emblem or related things) mean "0", while "tails" (reverse; usually shows the value of a coin) mean "1";
- it (the generation) starts with the least significant bit;
- the bits with larger weights are written to the left of the lesser ones.
What number is it? Let's put
Legend:
- n
- Position number (bit number)
- 2n
- Position weight (bit weight)
- an
- Position digit (bit value)
n | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
---|---|---|---|---|---|---|---|---|
2n | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
an | 1 | 0 | 1 | 0 | 1 | 0 | 1 | 0 |
Calculation:
a = 0*1 + 1*2 + 0*4 + 1*8 + 0*16 + 1*32 + 0*64 + 1*128 = 170So, the binary "10101010" equals "170" in the common decimal system.
Note: yes, it's a bit slow, but it can also train your brain's arithmetic performance a little, as a side effect ;-)
External (Wikipedia) links:
No comments:
Post a Comment