How to Generate Random Numbers

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Created: kiran10182 (04 May 2007)
Last edited: hamishwillee (26 Jul 2012)
Reviewer Approved    Thumbs up icon sm.jpg

Following Code snippet shows "How to generate random numbers" with Symbian C++ programming.

Header required:

#include <e32math.h>


const TUint KRandomNumberSize = 6;
TBuf<KRandomNumberSize > CYrAppUi::GenerateRandom()
TBuf16<KRandomNumberSize> random(_L(""));
//Generate the random number of 6 Digits
TInt i;
for (i=0; i<KRandomNumberSize ; i++)
TInt num = Math::Random() % 10;
TBuf<1> nTmp;
return random;

Use it as below:

TBuf<KRandomNumberSize> random(GenerateRandom());

Thus random descriptor will have 6 digits random number. User can change the value of KRandomNumberSize according to his/her needs.

This page was last modified on 26 July 2012, at 05:38.
41 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.


Thank you!

We appreciate your feedback.