Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hi, im a newbie here...
Can any one show me a sample program for generating random number like 1,4,7,10,13,16,19........
i need it in c program i'm trying this but it just produces a random number... i need it in a sequence... so please help!!!!!!!
#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 ());
system ("PAUSE");
}
return 0;
}
Hi, im a newbie here...
Can any one show me a sample program for generating random number like 1,4,7,10,13,16,19........
i need it in c program i'm trying this but it just produces a random number... i need it in a sequence... so please help!!!!!!!
#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 ());
system ("PAUSE");
}
return 0;
}
use the numbers to populate an array, then sort the array. Figure out how to code this and you've learned something.
Edit: this is really a question about programming in C.
-Viz
Can any one show me a sample program for generating random number like 1,4,7,10,13,16,19.....
This is not a set of random numbers; this is a sequence of numbers which begins with the number 1, adds 3 to the first number, adds 3 to the to the second sum, etc. What's so difficult about that?
I mean, really, it isn't even as difficult at a Fibonacci series, which isn't all that difficult. But it is a bit more difficult than a simple series incremented by three at each increase.
number=1 to start the series
followed by
number+=3 to continue the series
Last edited by bigrigdriver; 02-21-2008 at 05:22 PM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.