r/C_Programming • u/Skollwarynz • 8d ago
Project I built SkollDice — an open-source, truly randomized dice roller and Discord bot written in pure C
Hello everyone! I'm a student who loves C and D&D!
I always found it troublesome that most dice generators rely on pseudo-random number generators. So, I decided to solve this problem by myself!
Over the last few weeks, I created a desktop app using LVGL for the GUI and Concord for a Discord bot to generate SkollDice my first truly open-source code. It's a truly random dice roller that, /urandom on POSIX systems and RtlGenRandom on Windows produces normalized random numbers. To be more precised each number (each result) is extracted from urandom, and through the use of the simple discard method the result is then normalized. I'm currently developing the smartphone version, hoping to use as much C as possible. Any ideas on how to do it?
AI usage: I personally created the program. The project was both an experiment and an excuse to study more C. I used AI to search for the simple discard method (the method used to normalize the random number generated from /dev/urandom) and to help me explain how it works. I then personally created the code, and if you want, I can explain it more precisely in a comment.
On the other hand, I then used AI to search for libraries for GUI and Discord API, such as LVGL and CONCORD. Then the last use was for debugging and quickly creating functions or simple setups like "How can I create a grid with 2 elements?" and then I used this example to change or apply it to my structure.
The real 'sloppy' part was the CMake because this was my first open-source project, and I discovered (through AI search) the possibility to create different executables for different OS. I really enjoyed the idea, so I tried to organize the project to be useful and distributed to all possible people, both coders (who can git clone and use it) and normal D&D or RPG players (that want just an executable to download and use).
Here the official links of the program:
official website: https://skollwarynz.github.io/SkollDice/
official repo on codeberg: https://codeberg.org/Skollwarynz/SkollDice
github mirror: https://github.com/Skollwarynz/SkollDice
11
u/Physix_R_Cool 8d ago
most dice generators rely on pseudo-random number generators
It's a truly random dice roller that,
/urandomon POSIX systems andRtlGenRandomon Windows produces normalized random numbers.
Just because you seed from /urandom doesn't mean your numbers aren't pseudorandomly generated, no?
5
u/Lyraele 8d ago
There's no such thing as truly random with computers. Though you can get close enough that it mostly doesn't matter.
1
u/mrheosuper 8d ago
Why can't it be true random ?
1
u/Lyraele 8d ago
https://en.wikipedia.org/wiki/Random_number_generation if you want a good and quick overview.
3
u/mrheosuper 8d ago
I mean, the wiki said there can be true RNG
2
u/Lyraele 8d ago
Nit purely with software, no. Read it more carefully!
1
1
u/ChapterOld4443 4d ago
urandom tho collectes stuff from ur pc ddrivers devices and even from IO devices all to form this entropy so how can this not be , a truly random number , also i advice you to check csrng too
1
u/Skollwarynz 7d ago
Now I extract directly from urandom each number so each number is fully randomized from the entropy of the computer. The result is then normalized by the simple discard method so that the number generated are distribuited on the Gaussian curve. On the official webiste I even extracted the different result of something like 100000000 rolls for each type and the duscard is only about 0.1% for D4 and D6 whule other are lower than 0.1%
3
u/questron64 8d ago
I remember way back in the day, in the 90s, I wrote an IRC bot. It had a dice rolling feature, you could do !roll 3d6 and stuff. Someone did !roll 99999999d6 and my CPU went nuts. I was running Windows 95 on a 486 so while that doesn't seem like such a big deal on a modern computer, it ground my computer to a halt. Check your bounds, guys.
1
u/Skollwarynz 7d ago
Oh yeah the idea was that DnD player and PRG don't have to generate so high number, but I'll check for this type of boundry, thanks for the suggestion!
3
u/AutoModerator 8d ago
Hi /u/Skollwarynz,
Your submission in r/C_Programming was filtered because it links to a git project.
You must edit the submission or respond to this comment with an explanation about how AI was involved in the creation of your project.
While AI-generated code is not disallowed, low-effort "slop" projects may be removed and it's likely that other users push back strongly on substantially AI-generated projects.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
2
u/Limp-Confidence5612 8d ago
Cause urandom is not a pseudo random number generator...
1
u/Skollwarynz 8d ago
Because the generation of number from entropy is based on a more random aspect and in the end using the simole discard method you can go as near as possible to the perfect mathematical statistic. I understood from comment that even my methods has ita limits but in this case the generation doesn't rely on the time of machine or easy seeds so is more difficult to break and predict
1
u/sciencekm 8d ago edited 8d ago
I'm not a big fan of duplicating code. If I were to do this:
#if defined(_WIN32) || defined(_WIN64)
uint8_t windows_random(int divisor){
int limit = (256 / divisor) * divisor;
uint8_t random_byte;
do {
RtlGenRandom(&random_byte, sizeof(random_byte));
} while (random_byte >= limit);
int result = (random_byte % divisor) + 1;
return result;
}
#else
uint8_t simple_discard_method(int divisor, FILE *rand_reader) {
int limit = (256 / divisor) * divisor;
uint8_t random_byte;
do {
fread(&random_byte, sizeof(uint8_t), 1, rand_reader);
} while (random_byte >= limit);
int result = (random_byte % divisor) + 1;
return result;
}
#endif
It would simply be:
#if !_WIN32
#define RtlGenRandom(b,n) fread(b, n, 1, rand_reader)
#endif
uint8_t windows_random(int divisor){
int limit = (256 / divisor) * divisor;
uint8_t random_byte;
do {
RtlGenRandom(&random_byte, sizeof(random_byte));
} while (random_byte >= limit);
int result = (random_byte % divisor) + 1;
return result;
}
1
u/Skollwarynz 8d ago
Ah yeah you're right, thank you for the suggestion. I just discovered during this project that I could use #ifdef for OS code definition. I will fix that on my code thank you!
•
u/github-guard 8d ago
🔍 GitHub Guard: Trust Report
⚠️ This project scored 2/6 — below this subreddit's threshold of 3.
Audit Breakdown: * ❌ Low Star Count (⭐ 0 / 4 required) * ❌ New Repository (under 30 days old) * ✅ Licensed under MIT * ❌ No Security Policy — what is this? * ℹ️ Individual Contributor * ✅ Signed Commits