Inspiration
I wanted to use this opportunity to dive deeper into the Math of PRNG and TRNGs. It was quite the treat and came across a bunch of papers discussing some really fast and efficient generators that have come up recently (like the xorshift family of algorithms). I also wanted to continue on the new language train from last week's challenge.
I had picked up Swift as my new language last week and I am using the same repository to keep all the small Swift projects I take up over the next few weeks. If any of the projects grow, I will move them to a different repository. The PRNG directory added today is my contribution to the repo today.
What it does
It's a Swift executable package set up with command line options. I'm using the Linear Congruential Generator with the values for the multiplier, increment, and modulus picked up from Numerical Recipes. Build the PRNG executable, and move into the debug directory
swift build
cd .build/debug
Use the -h or --help to see a list of all options and flags available.
./prng -h
How I built it
I implemented the algorithm from scratch on Swift and used the ArgumentParser package to set up the command line interface.
Challenges I ran into
Figuring out small things like what library has the exponentiation function (it's Darwin for pow()), how pass by reference works in Swift and the interfaces available. I was initially using the CommandLine API to check for arguments but it quickly got out of hand and I had to switch to ArgumentParser.
Accomplishments that I'm proud of
Starting out with the PRNG algorithms took a while but I managed to narrow it down to one for this project.
What's next for Pseudo Random Generator
- Refactor Code: move the RNG implementation to a separate file and remove the hacky global variables
- Set up the generator to interface with Swift random functions, like
Int.random() - Add other algorithms
Built With
- cli
- swift
Log in or sign up for Devpost to join the conversation.