Hi all
how do load vars with random values ?
for example I need 3 random integers from 1 to 10 1 in each in each var .
What is the C code for declaring 3 integer variables loaded with a random integer for 1 to 10 each ?
Thanks Elico
As I said I need to declare 3 variable like var1, var2, var3 each will be assinged with a random int from 1 to 10 ,
What is not clear ?
Elico
Look up the C library functions srand, rand.
What kind of 'random' do you need?
- 'True' random numbers (like readings of a Geiger counter)? - Pseudorandom? The latter can be cryptographically secure or not. - Fixed 'random' numbers (like the one in my first post)?
All of the above are random numbers. But they are very different. Which one do you need? That's what is not clear.
It does not matter as long I can get an integer from 1 to 10 assign it in a var and use it to make decisions in the C code.
So what is the C code for declaring 3 vars amd assigning the random integers into them ?
what header files I need to use ?
thanks Elico
... and use it to make decisions in the C code
And it's OK if those decisions will be the same for each program run? If so, save yourself the trouble and use the numbers 7, 2 and 8. Because using header files like stdlib.h and functions like srand(), rand() won't be any better. Seriously.
It would be a bad day if the guy who wrote that response had anything to do with the boeing software.
Or just run a hardware timer, and use % 10. Whatever.
Those random numbers imitate "real" values that come in from the A2D ports . So they have to have random nature .
Is the guy who wrote this for real? Does he earn money from writing code?
Detail matters there. What happens if the timer is running at 100Hz and he makes 3 calls within 10ms to get the numbers only to find they're all the same.
Look pal, if you expect people to post ENTIRE SPECIFICATIONS for software you are at the wrong place. My posts are and were meant to stimulate ideas, not to offer a water tight solution. Grow up ! I had it.
Sorry chum. All they did with me was stimulate disbelief.
No good , I need new random integers all the time as the program runs . Can you show me a sample c code for what i asked .
I recommend that you try typing "random numbers in C" into a web search engine and look at some of the results. If you have specific problems, come back here and say something like: I tried ... and I got ..., but I expected ...
In J1708 when a collision happens, you add a random delay before you try again.; Once two units communicating via J1708 both using Keil collided, had I not stopped them they would still be colliding, BEWARE the rand function is NOT random it is pseudorandom
Erik
It doesn't hurt to make use of least-significant-bit noise from the ADC, or inter-packet delays on ethernet interface etc, to help out with some extra entropy. rand()/srand() alone can be quite boring to use.