Sponsored Content
Top Forums Shell Programming and Scripting generate random number in korn shell Post 94423 by frustrated1 on Friday 30th of December 2005 11:02:42 PM
Old 12-31-2005
generate random number in korn shell

I want to be able to generate a random number within a korn shell script..
Preferably i would like to be able to state how many digits should be in this random number... ie 4 digits or 5 digits etc

Any ideas?
 

10 More Discussions You Might Find Interesting

1. Programming

How to generate a random number?

How to generate a random integer with specific range(for example, from 1 to 1000)? Also, how to convert a floating point number into a integer? (2 Replies)
Discussion started by: MacMonster
2 Replies

2. Shell Programming and Scripting

how do i generate random integer using only shell script

Hi All, I need to generate 4 digit random no using only shell script. Please help in this ASAP. Thanks in advance... Regards, sridhar. (1 Reply)
Discussion started by: sridhusha
1 Replies

3. Shell Programming and Scripting

generate random number in perl

Could any one tell how can I generate random number from (0, 100..200) in perl? Thanks! (2 Replies)
Discussion started by: zx1106
2 Replies

4. Shell Programming and Scripting

Generate array name at run time Korn shell

Hi, I am trying to define number of array based on constant derived during execution phase of a script. Here is what i am trying.. #First Part, Get LUN input from User lun_count=4 count=0 set -A my_lun while : do while ]; do read L?"Enter Lun "$count" Number:" ... (2 Replies)
Discussion started by: harris2107
2 Replies

5. Programming

Generate random number

I saw this formula to generate random number between two specified values in shell script.the following. $(((RANDOM%(max-min+divisibleBy))/divisibleBy*divisibleBy+min)) Give a example in book. Generate random number between 6 and 30.like this. $(((RANDOM%30/3+1)*3)) But I have a... (1 Reply)
Discussion started by: luoluo
1 Replies

6. Shell Programming and Scripting

Unix random number generate in given range

Hi All, I have extracted some report from database for few activities done. Now I have a requirement to add some random time(In range of 10-35) in front of each activity. Can be generated random numbers in any bash/sh shell within a given number range, let's say in between 10-30. ... (10 Replies)
Discussion started by: gr8_usk
10 Replies

7. UNIX for Dummies Questions & Answers

how to generate random number as as the first column of a txt file

Dear all, I have a question. I have a txt file say 4000 rows X 1800 Column. I 'd like to creat a new column as the first column which is a column of random numbers (n=4000) thanks a lot! Lin (2 Replies)
Discussion started by: forevertl
2 Replies

8. Shell Programming and Scripting

Need to generate a file with random data. /dev/[u]random doesn't exist.

Need to use dd to generate a large file from a sample file of random data. This is because I don't have /dev/urandom. I create a named pipe then: dd if=mynamed.fifo do=myfile.fifo bs=1024 count=1024 but when I cat a file to the fifo that's 1024 random bytes: cat randomfile.txt >... (7 Replies)
Discussion started by: Devyn
7 Replies

9. Shell Programming and Scripting

Help with generate a pair of random number

Hi, Is anybody experience generate a pair of random number by using awk command? I wanna to generate a pair of random number (range from 1 to 4124) and repeats it 416 times. Desired output 2 326 123 1256 341 14 3245 645 . . . I did write the below command: awk... (5 Replies)
Discussion started by: perl_beginner
5 Replies

10. OS X (Apple)

Generate a random number in a fully POSIX compliant shell, 'dash'...

Hi all... Apologies for any typos, etc... This took a while but it didn't beat me... Although there are many methods of generating random numbers in a POSIX shell this uses integer maths and a simple C source to create an executable to get epoch to microseconds accuracy if it is needed. I take... (8 Replies)
Discussion started by: wisecracker
8 Replies
random(3M)																random(3M)

NAME
random(), srandom(), initstate(), setstate() - generate a pseudorandom number SYNOPSIS
DESCRIPTION
The and functions are random-number generators that have virtually the same calling sequence and initialization properties as the and func- tions, but produce sequences that are more random. The low 12 bits generated by the function go through a cyclic pattern, while all the bits generated by the function are usable. For example, produces a random binary value. The function uses a nonlinear additive feedback random-number generator employing a default state array size of 31 long integers to return successive pseudorandom numbers in the range from 0 to The period of this random-number generator is approximately 16 x The size of the state array determines the period of the random-number generator. Increasing the state array size increases the period. With 256 bytes of state information, the period of the random-number generator is greater than Like the function, the function produces by default a sequence of numbers that can be duplicated by calling the function with a value of 1 as the seed. The function initializes the current state array using the value of seed. The and functions handle restarting and changing random-number generators. The function allows a state array, pointed to by the state argument, to be initialized for future use. The size argument, which specifies the size in bytes of the state array, is used by the func- tion to decide how sophisticated a random-number generator to use; the larger the state array, the more random the numbers. Values for the amount of state information are 8, 32, 64, 128, and 256 bytes. Amounts less than 8 bytes return a NULL pointer, while other amounts are rounded down to the nearest known value. The seed argument specifies a starting point for the random-number sequence and provides for restarting at the same point. The function returns a pointer to the previous state information array. Once a state has been initialized, the function allows switching between state arrays. The array defined by the state argument is used for further random-number generation until the function is called or the function is called again. The function returns a pointer to the pre- vious state array. After initialization, a state array can be restarted at a different point in one of two ways: The function can be used, with the desired seed, state array, and size of the array. The function, with the desired state, can be used, followed by the function with the desired seed. The advantage of using both of these functions is that the size of the state array does not have to be saved once it is initialized. RETURN VALUE
The function returns the generated pseudorandom number. The function returns no value. Upon successful completion, the and functions return a pointer to the previous state array. Otherwise, a NULL pointer is returned. ERRORS
If the function detects that the state information has been damaged, error messages are written to standard error. SEE ALSO
drand48(3C), rand(3C), random(7). STANDARDS CONFORMANCE
random(3M)
All times are GMT -4. The time now is 05:56 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy