I desired to implement random: Pass or Fail, code.
So I generate random and store in on fRand.
fRand = GenerateRandomNumber();
if(fRand<0.5)then
//Pass
else
//Fail
Endif
But fRand always return less than 0.01. — this is very weird, I know this is still random, but is still not proportion.
This is the code I use to produce random numbers that have some solid offset.
You can mess with the offset numbers and get them to where you need them.
Hi Philip, I have few Generate Random command on other charts that are running concurrently.
But this one is interesting. It always generate less around 0.00nn
Yes, I tried to call SeedRandomNumber(), but results did not change.
I will try to use fRandom = sine (GenerateRandomNumber()); I am still thinking how the formula should look like to increase frequency (shorten the period).
So the others work properly and this one doesn’t? Are you sure fRand is not getting changed in another chart? Something isn’t right. Can you run just his code and disable the rest of your charts and see if it works?
Looks like the random recipe is working… others not.
I might use the sine function.
But GenerateRandomNumber is very weird, maybe because I am using softpac installed on Azure Cloud Virtual Windows?
If you take a look at the PAC Control command reference (included in PAC Control on your computer via the help menu, or from our website) you can see some details and hints about the random number.
From here you can do the math you need to get the range of numbers you need.
Try putting a few variables in and changing them in debug mode.
You will quickly find the offset you need to get the range of numbers are you looking for.
Does this help you get started?
I put this code together that multiplies by a scaling value, then uses offsets to get the correct ranges and allow for negative numbers. I also added rounding since it looks like you just want integers for the first two ranges, but 1000th’s on the third.
// +1 to +1000.
random[0] = Round(GenerateRandomNumber() * 1000) + 1;
// 0 to +2000, offset -1000 for -1000 to +1000.
random[1] = Round(GenerateRandomNumber() * 2000) - 1000;
// 0 to 200, offset -100, multiply by 1000 and round to get three extra places, then divide back to -100.000 to +100 range.
random[2] = Round((GenerateRandomNumber() * 200 - 100) * 1000) / 1000;