web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :

Random number generator in ax 2012

Chaitanya Golla Profile Picture Chaitanya Golla 17,225

Hi,

If we want to generate a random number between given range then we can make use of class RandomGenerate. In the below example, I tried to display a random date between dateNull(minimum date) and dateMax(Maximum date).

static void AXC_RandomYear(Args _args)
{
    int i;
    int randomNumber;
    RandomGenerate randomGenerate;

    randomGenerate = RandomGenerate::construct();
    randomGenerate.parmSeed(new Random().nextInt());
    for (i = 1; i <= 5; i++)
    {
        randomNumber = RandomGenerate.randomInt(year(dateNull()), year(dateMax())); // Generates random number within the range datenull and dateMax
        info(strFmt("%1", mkDate(1,4,randomNumber)));
    }
}

Output:

Random.png

To get more insight about the class you can check below link:

(RandomGenerate Class [AX 2012])

https://msdn.microsoft.com/en-us/library/randomgenerate.aspx

Comments

*This post is locked for comments