Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This 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!


Closed Thread
  Search this Thread
Old 02-21-2008, 10:53 PM   #1
LQ Newbie
Registered: Feb 2008
Posts: 3

Rep: Reputation: 0
Generate random numbers in C program

Hi, im a newbie here...
Can any one show me a sample program for generating real number like 1,4,7,10,13and 16
i need it in c program i'm trying this but it just produces a real number... i need it in a sequence... so please help!!!!!!!
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main(void)

int range;

srand (time(NULL));
range= (3-3)+1;

printf (" %d ", rand() %range +10);
printf (" %d ", rand() %range +10);
printf (" %d ", rand() %range +10);
printf (" %d ", rand() %range +10);
printf (" %d ", rand() %range +10);
printf (" %d\n ", rand() %range +10);
system ("PAUSE");
return 0;
Old 02-22-2008, 12:39 AM   #2
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914
Please post your thread in only one forum. Posting a single thread in the most relevant forum will make it easier for members to help you and will keep the discussion in one place. This thread is being closed because it is a duplicate.

Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Generate random numbers in C program ssaslam Linux - Newbie 5 10-23-2008 09:28 PM
using /dev/random to output random numbers on a text file guguma Programming 4 04-02-2007 02:42 PM
Generate random number with C++ TruongAn Programming 5 11-09-2005 01:01 AM
Creating random numbers from shell with /dev/random khermans Linux - General 1 07-13-2004 01:12 PM
Generating random numbers for C program J-Stew Programming 14 02-06-2004 05:49 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:57 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration