Skip to content

Commit 41c7df0

Browse files
Merge pull request #723 from Quantum-Software-Development/FabianaCampanari-patch-1
Update README.md
2 parents a271005 + e2922ce commit 41c7df0

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1816,6 +1816,46 @@ After running Solver, you should get a solution like:
18161816
<p align="center">
18171817
<img src="https://github.com/user-attachments/assets/54f0b665-87df-4cda-b52d-0efa01b33580"/>
18181818

1819+
<br>
1820+
1821+
## Modulo in Random Number Simulations
1822+
1823+
### Animated Visualization of the Remainder from Integer Division Used in Random Number Simulations.
1824+
1825+
<br>
1826+
1827+
<p align="center">
1828+
<img src="https://github.com/FabianaCampanari/University-Python-Projects/assets/113218619/176fd74d-5755-4ac0-9b6e-08e6678cf251"/>
1829+
1830+
1831+
The modulo operator (%) returns the remainder of a division. In simulations involving random numbers, it is commonly used to restrict or map large random outputs into a defined range.
1832+
1833+
### [Why Use Modulo in Random Number Simulations]() ?
1834+
1835+
In simulations, we often need random values within a specific interval — for example, simulating a dice roll (1 to 6) or selecting a random day of the week (0 to 6). Random number generators typically produce large numbers, so the modulo operation helps normalize these into the desired range.
1836+
1837+
### [Example]():
1838+
1839+
Imagine your random number generator gives you a number like 247. If you want to simulate a 6-sided dice roll:
1840+
1841+
dice_roll = (247 % 6) + 1 # Adding 1 to shift range from [0–5] to [1–6]
1842+
1843+
This ensures the result is always between 1 and 6.
1844+
1845+
Simulation Use Case:
1846+
1847+
In a banking simulation, you might simulate customer behavior across 7 days of the week. If a random function returns a number like 123456, you can use:
1848+
1849+
day_of_week = 123456 % 7 # Result is between 0 and 6
1850+
1851+
This maps any large number into the range of weekdays (e.g., 0 = Sunday, 6 = Saturday).
1852+
1853+
<br>
1854+
1855+
### [Summary]():
1856+
1857+
In simulations, the % operator is a simple and efficient way to control the range of random outputs. It transforms raw random data into usable, context-specific values, essential for realistic and accurate simulation scenarios.
1858+
18191859

18201860

18211861
<!--

0 commit comments

Comments
 (0)