Skip to content

Commit da4663a

Browse files
committed
perf(rng): add pseudo random number generation assignment
1 parent 2b09f96 commit da4663a

3 files changed

Lines changed: 54 additions & 5 deletions

File tree

artificialintelligence/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
| Week | Date | Topic | Assignment |
44
|------|------------|-----------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------|
5-
| 1 | 2023/01/16 | [Introduction]() | [Beecrowd](assignments/flocking/README.md) [Flocking](https://github.com/InfiniBrains/mobagen/tree/master/examples/flocking) |
6-
| 2 | 2023/01/23 | [Behavior and Decision trees, State machines]() | [Flocking](https://github.com/InfiniBrains/mobagen/tree/master/examples/flocking) |
5+
| 1 | 2023/01/16 | [Introduction]() | [Beecrowd](assignments/flocking/README.md) [MoBaGEn](https://github.com/InfiniBrains/mobagen/tree/master/examples/flocking) |
6+
| 2 | 2023/01/23 | [Behavior and Decision trees, State machines]() | [Beecrowd](assignments/flocking/README.md) [MoBaGEn](https://github.com/InfiniBrains/mobagen/tree/master/examples/flocking) |
77
| 3 | 2023/01/30 | [BFS, DFS, Procedural Content Generation - Mazes]() | [Maze](https://github.com/InfiniBrains/mobagen/tree/master/examples/maze) |
88
| 4 | 2023/02/06 | [BFS, DFS, Procedural Content Generation - Mazes]() | [Maze](https://github.com/InfiniBrains/mobagen/tree/master/examples/maze) |
99
| 5 | 2023/02/13 | [Spatial Quantization and Partitioning]() | [Catch the Cat](https://github.com/InfiniBrains/mobagen/tree/master/examples/catchthecat) |
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Pseudo Random Number Generation
2+
3+
You are a game developer in charge to create a fast an reliable random number generator for a procedural content generation system. The requirements are:
4+
5+
- Do not rely on external libraries;
6+
- Dont need to be cryptographically secure;
7+
- Be blazing fast;
8+
- Fully reproducible via automated tests if used the same seed;
9+
- Use exactly 32 bits as seed;
10+
- Be able to generate a number between a given range, both inclusive.
11+
12+
So you remembered a strange professor talking about the xorshift algorithm and decided it is good enough for your use case. and with some small research you found a the Marsaglia "Xorshift RNGs". You decided to implement it and test it.
13+
14+
## XorShift
15+
16+
The xorshift is a family of pseudo random number generators created by George Marsaglia. The xorshift is a very simple algorithm that is very fast and have a good statistical quality. It is a very good choice for games and simulations.
17+
18+
`xorshift` is the process of shifting a number and then `xor`'ing it to the original value to create a new value.
19+
20+
```value = value xor (value shift by number)```
21+
22+
The shift operators can be to the left `<<` or to the right `>>`. When shifted to the left, it is the same thing as multiplying by 2 at the power of the number. When shifted to the right, it is the same thing as dividing.
23+
24+
The `xorshift` algorithm from Marsaglia is a combination of 3 `xorshifts`:
25+
26+
1. `xorshift` the seed by `13` bits to the left;
27+
2. `xorshift` the seed by `17` bits to the right;
28+
3. `xorshift` the seed by `5` bits to the left;
29+
4. the current state of the seed is your current random number from $0$ to $2^{32}-1$.
30+
31+
In order to clamp a random number the value between two numbers (max and min), you should follow this idea:
32+
33+
```value = min + (random % (max - min + 1))```
34+
35+
## Input
36+
37+
Receives the seed, the number of random numbers to be generated and the range of the numbers should be in. The range is inclusive. All numbers are unsigned 32 bits integer.
38+
39+
```
40+
1 1 0 99
41+
```
42+
43+
## Output
44+
45+
The list of numbers to be generated, one per line.
46+
47+
```
48+
WiP
49+
```

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
"style": "cmake --build buildStyle --target fix-format",
1414
"prebuildall": "cmake -S. -Bbuild -DENABLE_TEST_COVERAGE=OFF -DENABLE_STANDALONE=ON -DENABLE_DOCUMENTATION=OFF",
1515
"buildall": "cmake --build build -j20",
16-
"generate:docs": "cmake -S. -BbuildDocs -DENABLE_TEST_COVERAGE=OFF -DENABLE_STANDALONE=ON -DENABLE_DOCUMENTATION=ON",
17-
"prebuild:docs": "npm run generate:docs",
18-
"build:docs": " cmake --build buildDocs --target GenerateDocs",
16+
"generate:docs": "CI=1 cmake -S. -BbuildDocs -DENABLE_TEST_COVERAGE=OFF -DENABLE_STANDALONE=ON -DENABLE_DOCUMENTATION=ON",
17+
"prebuild:docs": "CI=1 npm run generate:docs",
18+
"build:docs": " CI=1 cmake --build buildDocs --target GenerateDocs",
1919
"preserve": "npm run build:docs",
2020
"serve": "npx http-serve site",
2121
"serve:dev": "mkdocs serve"

0 commit comments

Comments
 (0)