LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to generate a random number with at least 6 digits?

Hi all,

All is in the question. 🙂

I would like to generate a random number but the function "random
number" in Labview isn't accurate enough.

Do you know an algorithm to generate a random number of 6 or more
digit?

Thanks,

PF
0 Kudos
Message 1 of 11
(6,723 Views)
pfg158,
I don't think there is a issue with the accuracy of the 'Randoem Number' function in labview. It's datatype is double-precision floating-point with approx 15 decimal digits of precision.

It does generate a number with 15 digits, to view this you can create a indicator and change the digits of precision to anywhere from 6 to 15 and you would able to observe this.

Find attached below a small program which demonstrates this.

Hope this helps,

Pravin
0 Kudos
Message 2 of 11
(6,723 Views)
Hi PF,
It's simple. Use 2 random number functions in the same process. Now you
should have 2 distinct random numbers that have the same accuracy. Let's say
LV gives accuracy up to the thousandth (0.XXX), now if you divide one number
by 1000 and then add to the other number you should then have something like
0.XXXXXX. Actually, LV random number function can give up to about 17 digits
(decimal). If you are looking for more digits (>17 digits), the idea above
may not work, then the last thing you may want try is to generate two or
three random numbers then convert all these decimal numbers to fractional
strings chop off the 0 and dot then concatinate them together. After all
it's still a random number. How many digits do you want to get? Make sure
the indicators acce
pt that many digits?

Good luck

Louis.

P-F wrote in message
news:8b43331a.0208270619.7335481a@posting.google.com...
> Hi all,
>
> All is in the question. 🙂
>
> I would like to generate a random number but the function "random
> number" in Labview isn't accurate enough.
>
> Do you know an algorithm to generate a random number of 6 or more
> digit?
>
> Thanks,
>
> PF
0 Kudos
Message 3 of 11
(6,723 Views)
Thnaks Pravin but I can't open your vi becaus I have Labview 6.0 and not the 6.1...
0 Kudos
Message 4 of 11
(6,723 Views)
All you need to do is change the 'Digits of Precision' (found in 'Format & Precision' on the front panel) to whatever number of digits you want (up to 18). This will show you a random number of the required length.

However, the whole 18 digits are stored in the number each time, so if you want 6 digits and no more, then multiply the random number by 1000000, round to nearest integer value, then divide by 1000000. this will then give you the exact value.

See the attached example (in LV 6.0). I hope this helps you..

Kim
0 Kudos
Message 5 of 11
(6,723 Views)
Thank you all,

I think it's not really a problem of precision.

However, I have another issue. What is the minimum step between two values given by the Random Number function?
So, is it possible to have all the values between 0.000001 and 0.999999?

Thanks for your help!

PF
0 Kudos
Message 6 of 11
(6,723 Views)
In fact, my goal is to have a random number for exemple between 1 and 1000000 with a step of 1.
My final aim is to simulate a bit error rate of from 10E0 to 10E-6 or 10E-8...
0 Kudos
Message 7 of 11
(6,723 Views)
In answer to your 2nd question, the random number function will produce values from between 0 and 1 with 18 digits of precision, in a uniform distribution. It is unlikely you'd get a value lower than 0.000001, or higher than 0.999999, but if you need numbers only in this range, then you can check each number is in range as it is generated, and if it isn't, then discard that number, and generate another number.

See the attached example (in LV 6.0).

Kim
0 Kudos
Message 8 of 11
(6,488 Views)
I have created a VI for you which generates a random number between 1 and 1000000 with a step of 1. Unfortunately i'm not sure what you mean about the bit error rate, but this example covers your goal as far as i can see.

Kim
0 Kudos
Message 9 of 11
(6,723 Views)
You should be able to open this VI now, i saved it for labview 6.0
0 Kudos
Message 10 of 11
(6,723 Views)