LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-15-2005, 09:50 AM   #1
huno
Member
 
Registered: May 2002
Distribution: Slackware 9.1
Posts: 161

Rep: Reputation: 30
random arrays


hi people
i'm searching on google about random arrays .. but there is no enough tutorials .
how can i declare array with 10 random integer ?
 
Old 07-15-2005, 10:55 AM   #2
femistofel
LQ Newbie
 
Registered: Jul 2005
Distribution: fedora
Posts: 17

Rep: Reputation: 4
what language?

in C you create an array and then fill it with your random numbers, like

Code:
#include <stdlib.h>

int main() {
  int ra[10];
  int i;
  for(i=0;i<10;i++) {
    ra[i] = rand();
  }
}
man rand for details.
 
Old 07-15-2005, 02:05 PM   #3
huno
Member
 
Registered: May 2002
Distribution: Slackware 9.1
Posts: 161

Original Poster
Rep: Reputation: 30
the output as following :
--
1804289383
846930886
1681692777
1714636915
1957747793
424238335
719885386
1649760492
596516649
118964142
---
i need only 10 digits .. not all these numbers
 
Old 07-15-2005, 02:11 PM   #4
femistofel
LQ Newbie
 
Registered: Jul 2005
Distribution: fedora
Posts: 17

Rep: Reputation: 4
then you've gotta scale the numbers down.

change the

Code:
    ra[i] = rand();
to

Code:
    ra[i] = rand() % 10;
 
  


Reply



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
Argument Arrays saiz66 Programming 3 09-29-2004 10:55 PM
Searching through arrays Benr Linux - Newbie 1 09-21-2004 01:50 PM
Creating random numbers from shell with /dev/random khermans Linux - General 1 07-13-2004 12:12 PM
Arrays in C++ kalleanka Programming 5 02-07-2004 12:27 AM
help with arrays leroy27336 Programming 6 01-20-2004 06:07 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:16 PM.

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