Header Sep

Symbian OS Tips, Tricks & Code

My Rating Score
Login to rate page

February 2006

Random number generation in UIQ 3

The following example application uses a simple random number generation algorithm in order to show dice with random values on the screen. The dice are displayed both in the application space and in the application menu bar. 

Download example application>>

The screen shot below shows the running application:

The application can be useful when playing games that require one or more dice.

Random numbers can be generated using Math::Rand(). Another method for generating pseudo-random numbers is to use a mixed congruential generator as follows:

x(n+1) = (a*x(n)+b)) (mod m)

Here, a, b and m are constants which should be carefully chosen since only certain values will give good random numbers. From each value x(n), the next value in the sequence, x(n+1) can be computed.

The following table shows some specific congruential generators:

Name of source   A B     m
Lehmer 23 0 10^8+1  
Rotenberg 2^7+1   1 2^35
GGL  7^5 0 2^31-1
Neave 131 0 2^35
Wichmann-Hill 171 0 30269

The dice example application uses the Wichmann-Hill congruential generator.

In order to draw small dice in the menu bar, controls are added using the MQikViewContext interface:
 
MQikViewContext* viewContext = ViewContext();
CCoeControlArray& ca = viewContext->Controls();

The application icon that is shown in the upper left corner is changed using the following API:

CQikViewBase::SetAppTitleIconL();

To build the example application for UIQ 3-based phones, use the following commands:

$ bldmake bldfiles
$ abld build gcce urel
$ makesis random.pkg 

More information:

My Rating Score
Login to rate page