Forum Discussion
Unable to persist random values in M Language
- 6 years ago
Hello PaulCooper ,
That's good solution but I have found a workaround already.
Could you please explain this one:
PaulCooper wrote:I already use a Node.js script to write M code for the schema in to my Connector project.
How did you implement that? I'll be very appreciated for any info about that.
Hello PaulCooper
Have you found a solution for this issue?
I need to do something like that
Regards,
Alex
Sorry for the delay in responding.
I have solved it but not via M. I already use a Node.js script to write M code for the schema in to my Connector project. So I extended this to replace a placehoder in the unit testing file with a random intial seed (using Math.random()). I then use a simple function that uses a Linear Congruential pseudo-random number generator algorithm (See https://en.wikipedia.org/wiki/Linear_congruential_generator) to generate the next number from an input seed value and fixed values for the Multiplier, Increment and Modulo. (103867, 13751 and 65536 respectively. Note that the first two are primes and the Modulo is a power of 2). This output number is divided by the Modulo to give a decimal number between 0 to 1. This way I get deterministic random numbers. Please note the initial seed should be an integer between 0 and the Modulo - 1.
I use the initial seed added to an index number of entries in an array to create the input seed I pass to the function to create a list of random numbers between 0 and 1. I apply the test of "<0.5" to these numbers to choose which entries of the array I use. (Yes, I did use 0.2 in my original post.)
Every time the code is built a new initial seed is put in the unit test file and as the M code is deterministic if a test fails then it can report the values actually used.
- rcyber6 years agoResolver I
Hello PaulCooper ,
That's good solution but I have found a workaround already.
Could you please explain this one:
PaulCooper wrote:I already use a Node.js script to write M code for the schema in to my Connector project.
How did you implement that? I'll be very appreciated for any info about that.