26 Sept 2018

Generate random numbers in AX 2012

Sometimes required generate a random number between given range.
There is a class RandomGenerate for generate random numbers. 
See below example, My requirement generate random numbers with 9 digits .


static void AXExplorer_Randomnumber(Args _args)
{

    RandomGenerate randomGenerate;    
    int                          randomNumber;

    randomGenerate = RandomGenerate::construct();
    randomGenerate.parmSeed(new Random().nextInt());     
    randomNumber = RandomGenerate.randomInt(100000000, 999999999);  // need to specify range
    info(strFmt("%1", randomNumber));
    
}

No comments:

Create number sequence in D365 FO

Create the data type. Add code in the loadModule method of the appropriate NumberSeqModule subclass. Add a method to the module’s paramet...