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
my favorite random generator is a free running timer that is read when some asynchrounous event e.g. a button press happens.
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.
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
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 ...
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 .
Sorry chum. All they did with me was stimulate disbelief.
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.
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.
Those random numbers imitate "real" values that come in from the A2D ports . So they have to have random nature .
Elico
Or just run a hardware timer, and use % 10. Whatever.
It would be a bad day if the guy who wrote that response had anything to do with the boeing software.
... 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 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
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.
Look up the C library functions srand, rand.
View all questions in Keil forum