Skip to content
Maximilian Stadlmeier edited this page Jul 10, 2014 · 1 revision

Tutorial 01 : Basics

This tutorial will show you how to use the most basic functionality RUL has to offer.

First of all, include the RUL namespace with a using statement.

using RUL;

Generating random numbers

Random numbers are obviously at the core of this library, so this shouldn't require too much explanation. Simply call the appropriate function with the desired range.

int a = Rul.RandInt(10); //A random integer between 0 and 10 (10 excluded)
int b = Rul.RandInt(3,100); //A random integer between 3 and 100 (both included)
float c = Rul.RandFloat(); //A random float between 0 and 1
long d = Rul.RandLong(-1000,500) // A random long between -1000 and 500

There are, of course, more functions and overloads. Check out the reference for all of them.
With integers you can also specify which bounds you want to include. To do this, use the InclusionOptions enum.

int e = Rul.RandInt(10,InclusionOptions.Both); //A random integer between 0 and 10, both included
long f = Rul.RandLong(5,20,InclusionOptions.Upper); //A random long between 6 and 20

Seeding

RUL gives you control over the seed that the underlying pseudo-random-number generator uses.
This enables you to replicate the output of a previous session.

Rul.Initialize(1234);
Console.WriteLine(string.Format("{0}, {1}, {2}",Rul.RandInt(10),Rul.RandInt(10),Rul.RandInt(10)));
//Output : 7,1,3
Rul.Initialize(1234);
Console.WriteLine(string.Format("{0}, {1}, {2}",Rul.RandInt(10),Rul.RandInt(10),Rul.RandInt(10)));
//Output : 7,1,3

Note that you don't have to initialize RUL, unless you want a custom seed.