Tag: prng

Structuring libraries, basic design tips.

Posted by on August 28, 2009

One of the most important things a programmer has to know and learn is proper code design, structuring of the code, etc. This may not be imperative for you if you’re just starting out, but sooner or later you’ll be able to spot the patterns and realize that your current way of doing things is not optimal but rather cumbersome. This is when you start to separate things into modules and you begin to design your code with more meaning and purpose.

By breaking your code into modules or “classes” you can have a finer granularity of the code itself, you can encapsulate the base code and work on top of it, you can also reuse the code in other projects if you have a good design. An example would be a log library (for logging useful debugging information onto text files) with proper design and care you’ll be able to use the same library in almost all of your projects with little to no modification at all.

Random Floats using built-in PRNG

Posted by on June 13, 2009

Random floats are kind of a mystical thing in PB, however it can be achieved to a certain degree without having to stack calls on a per decimal fashion.

Here is a simple implementation that will get you going, this is meant specifically for games but it could find other uses…

Try it out yourself, if you need a wider range of numbers just multiply the result by a certain factor. I use this and other similar macros for most of my float random needs in PB. Should you need to stack the calls, just make procedures out of the macros.

Similar routines are found inside the Quake3 sources if you care to read them (hint: if you look carefuly there is a comment line inside the game source that reads “// What the fuck?” — Just priceless, seriously).