Sponsored Content
Top Forums Shell Programming and Scripting Random numbers from 0 to 1000 Post 302214939 by radoulov on Tuesday 15th of July 2008 07:41:03 AM
Old 07-15-2008
If the RANDOM variable is available:

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

 

9 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

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/httpd.pid 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. 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

7. 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

8. 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

9. 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
RANDOM(3)						     Library Functions Manual							 RANDOM(3)

NAME
random, srandom, initstate, setstate - better random number generator; routines for changing generators SYNOPSIS
long random() srandom(seed) int seed; char *initstate(seed, state, n) unsigned seed; char *state; int n; char *setstate(state) char *state; DESCRIPTION
Random uses a non-linear additive feedback random number generator employing a default table of size 31 long integers to return successive pseudo-random numbers in the range from 0 to (2**31)-1. The period of this random number generator is very large, approximately 16*((2**31)-1). Random/srandom have (almost) the same calling sequence and initialization properties as rand/srand. The difference is that rand(3) pro- duces a much less random sequence -- in fact, the low dozen bits generated by rand go through a cyclic pattern. All the bits generated by random are usable. For example, ``random()&01'' will produce a random binary value. Unlike srand, srandom does not return the old seed; the reason for this is that the amount of state information used is much more than a single word. (Two other routines are provided to deal with restarting/changing random number generators). Like rand(3), however, random will by default produce a sequence of numbers that can be duplicated by calling srandom with 1 as the seed. The initstate routine allows a state array, passed in as an argument, to be initialized for future use. The size of the state array (in bytes) is used by initstate to decide how sophisticated a random number generator it should use -- the more state, the better the random numbers will be. (Current "optimal" values for the amount of state information are 8, 32, 64, 128, and 256 bytes; other amounts will be rounded down to the nearest known amount. Using less than 8 bytes will cause an error). The seed for the initialization (which specifies a starting point for the random number sequence, and provides for restarting at the same point) is also an argument. Initstate returns a pointer to the previous state information array. Once a state has been initialized, the setstate routine provides for rapid switching between states. Setstate returns a pointer to the previous state array; its argument state array is used for further random number generation until the next call to initstate or setstate. Once a state array has been initialized, it may be restarted at a different point either by calling initstate (with the desired seed, the state array, and its size) or by calling both setstate (with the state array) and srandom (with the desired seed). The advantage of call- ing both setstate and srandom is that the size of the state array does not have to be remembered after it is initialized. With 256 bytes of state information, the period of the random number generator is greater than 2**69 which should be sufficient for most purposes. AUTHOR
Earl T. Cohen DIAGNOSTICS
If initstate is called with less than 8 bytes of state information, or if setstate detects that the state information has been garbled, error messages are printed on the standard error output. SEE ALSO
rand(3) BUGS
About 2/3 the speed of rand(3C). 4.2 Berkeley Distribution September 29, 1985 RANDOM(3)
All times are GMT -4. The time now is 05:40 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy