Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the algorithm for random numbers in X++? [AX]

What is the algorithm to have random reals using x++ in Dynamics AX?

like image 671
Tassisto Avatar asked Oct 29 '25 06:10

Tassisto


2 Answers

The old way (and only if using Axapta 3.0) is to use the Random class which is listed in the AOT under System Documentation\Classes. It will return a 15 bit integer only. See AX Daily.

But like Alex, I will prefer using the newer xGlobal::randomPositiveInt32().

dice = (xGlobal::randomPositiveInt32() mod 6) + 1;
like image 178
Jan B. Kjeldsen Avatar answered Oct 31 '25 13:10

Jan B. Kjeldsen


You can easily generate a positive int with this method, then just turn it into a real and divide after if you want decimals.

i = xGlobal::randomPositiveInt32();

like image 22
Alex Kwitny Avatar answered Oct 31 '25 12:10

Alex Kwitny