Quantcast
Channel: Microsoft Dynamics AX Forum - Recent Threads
Viewing all articles
Browse latest Browse all 73760

Random Number Generation

$
0
0

Hello,

 

We are implementing one functionality where we need to generate random number between 5 digits to 9 digits.

First I tried with 

//Job 1

Random Random = new Random();
int myrandomnumber;
;
myrandomnumber= Random.nextInt() ;

In above job it is generating random number of 5 digits and it seems everytime number starts with 30***. We tried to generate two random numbers and linked them.

Suppose we need to generate 7 digits number then 5 digit by above job and 2 digits by myrandomnumber= Random.nextInt() mod 100 ; and then linked them but it generates 1 digit number also. So we can not rely on this functions.

Then I tried to generate random number using 

//Job 2

RandomGenerate randomGenerate;
randomGenerate = RandomGenerate::construct();
randomGenerate.parmSeed(new Random().nextInt());

switch(numberOfDigits)
{

case 5:
RandomNo = randomGenerate.randomInt(10001,99999);
break;

case 9:
RandomNo = randomGenerate.randomInt(100000001,999999999);
break;
}

This is good option but in this while we are generating numbers of 9 digits mostly they are starting from 999/998/997. I never get number starting from 1 to 8. Can anyone explain why this is happening? Is there any alternate approach we can use to generate random numbers those are actually random?(any number from entire range)

Thanks in advance!

Regards,

Smit

 


Viewing all articles
Browse latest Browse all 73760

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>