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

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Generating Random Number

(0) ShareShare
ReportReport
Posted on by

Hi,

We have requirement of generating random numbers between  5 to 9 digits. We tried to generate number by functions

RandomNo1=Random.nextInt(); // it is generating number of 5 digits only
RandomwithMod=Random.nextInt() MOD y; //For additional digits over 5

Sometimes second code is generating less additional digits then require.

Is there any function in AX where we can generate random number of more than 5 digits?

Regards,

Smit Patel

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Vilmos Kintera Profile Picture
    46,149 on at
    RE: Generating Random Number

    You can use the .Net namespace to do that, it is natively supported by AX.

        System.Random       rnd = new System.Random();
        info(System.Convert::ToString(rnd.Next(10000, 999999999)));
    


  • Community Member Profile Picture
    on at
    RE: Generating Random Number

    Hi Vilmos Kintera,

    Thanks for a reply. We are getting number for number of digits like 5,6,7,8,9 from user. If user gives  then it should add 5 digit random number. If he gives 6 then 6 digit and so on.  Is there any function which will take argument as number of digits and give output?

    Regards,

    Smit

  • Martin Dráb Profile Picture
    236,289 Most Valuable Professional on at
    RE: Generating Random Number

    You can easily calculate the range for Next() by yourself. Like this:

    int length = ...
    
    lowest  = power(10, length - 1);
    highest = power(10, length) - 1;


Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Community Member Profile Picture

Community Member 4

#2
Nayyar Siddiqi Profile Picture

Nayyar Siddiqi 2

#2
Guy Terry Profile Picture

Guy Terry 2 Moderator

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans