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;
}
Popularity: 2% [?]
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
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!
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 Hide Data in Image, Audio & Video Files: Steganography
Ever wondered to know how to hide secret messages in images, audio and video files? Well, in this post I will take you through a concept called steganography using which, it is possible to hide your secret information …
INTERNET SECURITY »
How to Hide Data in Image, Audio & Video Files: Steganography
Ever wondered to know how to hide secret messages in images, audio and video files? Well, in this post I will take you through a concept called steganography using which, it is possible to hide your secret information …
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 …
Categories
Most Popular
Most Commented
Blogroll
Log In | Entries (RSS) | Comments (RSS) | Sitemap
© 2008-2011 GoHacking.Com. This content is copyrighted to Srikanth and may not be reproduced on other websites.