C Program to Generate Random Numbers
Submitted by Srikanth on Wednesday, 16 January 20087 Comments

This is a simple program to generate random numbers. This logic can be used to build a Lotto program or a program to pick Lucky number and so on. Here’s the program
#include<stdio.h>
#include <stdlib.h>
#include <time.h>
#include <stdlib.h>
#include <time.h>
int main(void)
{
int i;
time_t t;
srand((unsigned) time(&t));
printf(“Ten random numbers from 0 to 99\n\n”);
for(i=0; i<10;i++)
printf(“%d\n”,rand()%100);
}
OR
If it necessary to generate a number between 0 and (num-1) then this program meets the ideal solution
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
/* prints a random number in the range 0 to 99 */
int main(void)
{
randomize();
printf(“Random number in the 0-99 range: %d\n”, random (100));
return 0;
}
Popularity: 1% [?]
By using/following this site you agree to our Legal Disclaimer


Thats great! I’ve been looking all over for this solution, thanks!
More of a question to anyone, Is their a program to figure out what random number algorithm (prng)a computer is useing to generate random numbers.
hai sir,
could u please explain the working of function srand();
@ aditya
Refer http://www.cprogramming.com/tutorial/random.html
hi sirkanth ,
well i am newbie in C programming , just 15 years old and i am very curious about learning C programming . I am attending a course form a private institution and there they are very slow with the portions . SO i am thiking studying of my own , but will i get the logics required if i am learning my own to prgram looking at books
@ aswin
Studying on your own is the best way to learn.. In fact I learnt programming only through books and not from any other source..
I am totally new to C…can you help me with the code structure written above and what should I refer to learn C…
Please help me with it
And one more thing, from where shall I download the program C?
Awaiting Response
My email ID is “siddhant_shah@live.com”
Thanks
Leave your response!
EMAIL SECURITY »
What to do when your Email Account is Hacked?
How to Recover Hacked Email Accounts?
It can be a real nightmare if someone hacks and takes control of your email account as it may contain confidential information like bank logins, credit card details and other sensitive data. …
HOW-TO GUIDES »
How to Detect Anonymous IP Addresses
As the fraudsters are now becoming more sophisticated in bypassing the Geo-location controls by using proxies (Anonymous IPs) to spoof their IP address, it has become very much necessary to come up with a means …
INTERNET SECURITY »
How to Detect Anonymous IP Addresses
As the fraudsters are now becoming more sophisticated in bypassing the Geo-location controls by using proxies (Anonymous IPs) to spoof their IP address, it has become very much necessary to come up with a means …
NETWORK HACKS »
How to Hack an Ethernet ADSL Router
Almost half of the Internet users across the globe use ADSL routers/modems to connect to the Internet however, most of them are unaware of the fact that it has a serious vulnerability which can easily be exploited even by a …
VIRUS CREATION »
How to Test the Working of your Antivirus – EICAR Test
Have you ever wondered how to test your Antivirus software to ensure it’s proper working? Well here is a quick and easy way to test your antivirus. The process is called EICAR test which will …
Categories
Blogroll
Recent Comments
Most Commented
Most Popular
Log In | Entries (RSS) | Comments (RSS) | Sitemap