RLidster Posted May 20, 2015 Share Posted May 20, 2015 Hi There, I am working on a problem where i require a script to randomly generate a number between 1 and 3. I have used the function randuniform(1,3,1), however, this generates numbers with a huge number of decimal places. I only require the integer. I am curious to know if DAQFactory has an integer conversion function (like Int() ), i have seen the rounding functions however i don't want to add any bias. Can you suggest a way to output an integer without converting to a string parsing the string and reconverting the string back to an integer? regards Rich Link to comment Share on other sites More sharing options...
AzeoTech Posted May 20, 2015 Share Posted May 20, 2015 Sure, use floor() or ceil(). Floor() will strip the decimal. Ceil() will do the same as floor(), but add 1. So: floor(1.234) = 1 ceil(1.234) = 2 Note that there is only one integral number BETWEEN 1 and 3 Also, note that if you use floor(), which I suggest, you'll want randuniform to go from 1 to 3.9999, not 1 to 3, otherwise you'll basically never get 3. So: floor(randuniform(1,3.999999,1)) Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.