I want to know how can we generate a list of different random numbers in c.?
-
I want to know how can we generate a list of different random numbers in c. is there any function in c which can automaticaaly generate a list of different random numbers . plz help me.
-
Answer:
#include <stdio.h> #include <stdlib.h> #include <time.h> int main (int argc, char *argv[]) { /* Simple "srand()" seed: just use "time()" */ unsigned int iseed = (unsigned int)time(NULL); srand (iseed); /* Now generate 5 pseudo-random numbers */ int i; for (i=0; i<5; i++) { printf ("rand[%d]= %u\n", i, rand ()); } return 0; } This will produce five random numbers using the system clock as the seed. This ensures running back to back, the same random numbers are not generated. HTH - Good Luck, -Aaron
monal r at Yahoo! Answers Visit the source
Other answers
it depends on what do you mean by "different random numbers"... are you thinking about the distribution?! the std c func is rand(); you can set the seed of the random sequence with srand(number); the same seed gives the same sequence (this is property that is needed, not a proof of poor randomness) each time you call rand(), you obtain the "next" number of that sequence. rand() returns "random" (pseudorandom) intergers from 0 to RANDMAX. so if you need random num from 0.0 to 1.0, or others, you need a little bit of extra computation
Tizio 008
Related Q & A:
- How can you create a different page in Wordpress?Best solution by WordPress
- How can you erase a link on the tab that I don't want to have anymore?Best solution by Yahoo! Answers
- Does anyone in Saudi Arabia know how can a Saudi girl travel alone without her father's permission?Best solution by Yahoo! Answers
- I play the clarinet and I want to know if taking up trumpet would affect my clarinet technique.Best solution by Yahoo! Answers
- Emails are being sent to my entire contact list and I do not know how they are being sent?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.