C Program to Generate Random Numbers
Submitted by Srikanth on Wednesday, 16 January 20088 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;
}
Related Posts
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 “[email protected]”
Thanks
this is another way to do it
#include
using namespace std;
#include
#include
int main ()
{
int number;
//seeds the random number
srand(time(0));
//generates a # from 1 to 100
number = (rand()%100)+1;
//prints to screen
cout << random;
}
Leave your response!
I am the author and founder of GoHacking. You can read more about me or get in touch with me on Google+ or contact page.
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 STUFFS WORK »
How Antivirus Software Works
Due to ever increasing threat from virus and other malicious programs, almost every computer today comes with a pre-installed antivirus software on it. In fact, an antivirus has become one of the most essential software package for every computer. Even though every one …
HOW-TO GUIDES »
How to Retrieve Clipboard History in Windows
Ever copied a code snippet or text from the web and forgot to paste it before you copied something else? Well, all of us will have an experience of something like this, where we want to …
INTERNET SECURITY »
Access Your Facebook Account with 3 Passwords
Did you know that you can login to your Facebook account using 3 different passwords? Seems interesting isn’t it? Yep! Unlike any other online account which has only one password to access, Facebook lets you …
NETWORK HACKS »
Access Your Facebook Account with 3 Passwords
Did you know that you can login to your Facebook account using 3 different passwords? Seems interesting isn’t it? Yep! Unlike any other online account which has only one password to access, Facebook lets you …
Categories
Most Popular
Most Commented
Blogroll
Log In | Entries (RSS) | Comments (RSS) | Sitemap
© 2008-2012 GoHacking.Com. This content is copyrighted to Srikanth and may not be reproduced on other websites.