Visit Our UNIX and Linux User Community

Random numbers from 0 to 1000

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Random numbers from 0 to 1000
# 1  
Old 07-15-2008
Random numbers from 0 to 1000

Hello All,

I want to make a simple script which generate random number from 0 to 1000.
and simply display it.

Plz HELP!!!!!!

Waqas Ahmed
# 2  
Old 07-15-2008
try this:
num=$(( $RANDOM % 1001  ))
echo $num

Last edited by jim mcnamara; 07-15-2008 at 08:43 AM..
# 3  
Old 07-15-2008
If the RANDOM variable is available:

printf "%d\n" $(($RANDOM%1000+1))

Previous Thread | Next Thread
Test Your Knowledge in Computers #419
Difficulty: Easy
Few popular modern Web browsers support JavaScript with built-in interpreters.
True or False?

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to insert random numbers into each line?

I have a file contains thousands of lines. I want to insert n random numbers into each line at specific position. Like this: 0 22…… 1 33…… …… …… I want to insert 3 random numbers from position 2 to 4 into each line. 0 325 22…… 1 685 33…… …… …… Please use CODE tags when... (8 Replies)
Discussion started by: hhdzhu
8 Replies

2. Shell Programming and Scripting

Creating a sequence of numbers in a line for 1000 files

Hi, I try to explain my problem , I have a file like this: aasdsaffsc23 scdsfsddvf46567 mionome0001.pdb asdsdvcxvds dsfdvcvc2324w What I need to do is to create 1000 files in which myname line listing a sequence of numbers from 0001 to 1000. So I want to have : nomefile0001.txt that must... (10 Replies)
Discussion started by: danyz84
10 Replies

3. Homework & Coursework Questions

Random numbers

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! Write a shell script that will take the sum of two random number? Ex: Random n1 +Random n2 = result i tries to write it but i had some dufficulties ... (3 Replies)
Discussion started by: renegade755
3 Replies

4. Shell Programming and Scripting

[Solved] Help with random pick 1000 number from range 1 to 150000

Hi, Do anybody knows how to use awk or any command to random print out 1000 number which start from range 1 to 150000? I know that "rand" in awk can do similar random selection. But I have no idea how to write a code that can random pick 1000 number from range 1 to 150000 :confused: ... (1 Reply)
Discussion started by: perl_beginner
1 Replies

5. Shell Programming and Scripting

Replace a random string of numbers

Hi Can someone help me with this one? I have string.. (PROC_PROC_ID == 12183) <--PID is dynamic and i want to replace the PID number with whatever PID from /opt/hpws/apache32_2/logs/ file. i'm having problem since the PID on the string is dynamic. It may be 2-5 digits or more. ... (5 Replies)
Discussion started by: ryandegreat25
5 Replies

6. Programming

Random numbers in parent/child?

Hi I'm trying to generate random numbers both in parent process and the child process. But I get the same random number in both processes. Why doesn't it generate different numbers altough I seed random number generator? Here's my code: #include <stdio.h> #include <unistd.h> #include... (2 Replies)
Discussion started by: xyzt
2 Replies

7. Shell Programming and Scripting

Generating random numbers

Hi, I am having trouble with generating random numbers. can this be done with awk? So I have a file that looks like this: 23 30 24 40 26 34 So column1 is start and column2 is end. I want to generate 3 random #'s between start and stop: So the output will look like this: ... (9 Replies)
Discussion started by: phil_heath
9 Replies

8. Shell Programming and Scripting

Random Numbers - Perl

Hi Guys I have a script to find Ranomd numbers. But I want to make the file to produce more random. Could u guys help me plz. In this Script I have the code that generates random in for loop and the range I have specified in my %chromlength input and out put will be like this chrno start end... (3 Replies)
Discussion started by: repinementer
3 Replies

9. UNIX for Dummies Questions & Answers

Random numbers without repetition

Is anyone know some scripts to generate random number without repetition using bash; for example generate 10 different random numbers. Thanks (8 Replies)
Discussion started by: asal_email
8 Replies

Featured Tech Videos