This project demonstrates an interesting geometric phenomenon:
In higher-dimensional spaces, most of the volume of a hypersphere is concentrated near its outer shell.
The program generates random points uniformly distributed within a hypercube and selects those that fall inside a hypersphere of radius RADIUS. It then analyzes how many of these points lie within a thin outer shell of the sphere (between RADIUS - ε and RADIUS).
It uses modern C++17 features including:
std::threadandstd::atomicfor multithreadingstd::mutexfor safe shared state accessstd::arrayandstd::vectorfor efficient storage- Random number generation with
std::mt19937_64
You can build the project using the included Makefile:
makeBy default, the program uses:
-
C++17 -
Optimization flags like
-O3,-march=native,-flto -
Predefined macros:
DIMENSIONS=15AMOUNT=50000
To override them:
make CPPFLAGS='-DDIMENSIONS=20 -DAMOUNT=100000'Using threads: 6
Progress: 100% (50000/50000)
Sphere dimensions: 15
Points total: 50000
Points in outer sphere layer: 39746 (~79.492%)
Time elapsed: 35074.3 ms
As the number of dimensions increases, most of the points fall into the outer shell of the hypersphere. This program helps visualize this unintuitive result by statistical simulation.
make cleanThis project is released under the MIT License.