Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

srand(3) [netbsd man page]

RAND(3) 						   BSD Library Functions Manual 						   RAND(3)

NAME
rand, srand, rand_r -- bad random number generator LIBRARY
Standard C Library (libc, -lc) SYNOPSIS
#include <stdlib.h> void srand(unsigned int seed); int rand(void); int rand_r(unsigned int *seed); DESCRIPTION
These interfaces are obsoleted by random(3). The rand() function computes a sequence of pseudo-random integers in the range of 0 to RAND_MAX (as defined by the header file <stdlib.h>). The srand() function sets its argument as the seed for a new sequence of pseudo-random numbers to be returned by rand(). These sequences are repeatable by calling srand() with the same seed value. If no seed value is provided, the rand() function is automatically seeded with a value of 1. The rand_r() function is a reentrant interface to rand(); the seed has to be supplied and is maintained by the caller. SEE ALSO
random(3), rnd(4) STANDARDS
The rand() and srand() functions conform to ANSI X3.159-1989 (``ANSI C89''). The rand_r() function conforms to IEEE Std 1003.1c-1995 (``POSIX.1''). BSD
June 4, 1993 BSD

Check Out this Related Man Page

RAND(3) 						   BSD Library Functions Manual 						   RAND(3)

NAME
rand, rand_r, srand, sranddev -- bad random number generator LIBRARY
Standard C Library (libc, -lc) SYNOPSIS
#include <stdlib.h> int rand(void); int rand_r(unsigned *seed); void srand(unsigned seed); void sranddev(void); DESCRIPTION
These interfaces are obsoleted by arc4random(3). The rand() function computes a sequence of pseudo-random integers in the range of 0 to RAND_MAX (as defined by the header file <stdlib.h>). The srand() function sets its argument seed as the seed for a new sequence of pseudo-random numbers to be returned by rand(). These sequences are repeatable by calling srand() with the same seed value. If no seed value is provided, the functions are automatically seeded with a value of 1. The sranddev() function initializes a seed, using the random(4) random number device which returns good random numbers. However, the rand() function still remains unsuitable for cryptographic use. The rand_r() function provides the same functionality as rand(). A pointer to the context value seed must be supplied by the caller. SEE ALSO
arc4random(3), random(3), random(4) STANDARDS
The rand() and srand() functions conform to ISO/IEC 9899:1990 (``ISO C90''). The rand_r() function is as proposed in the POSIX.4a Draft #6 document. BSD
May 25, 1999 BSD
Man Page

13 More Discussions You Might Find Interesting

1. Solaris

Epoch time in Solaris

One way of getting epoch time in solaris is truss date 2>&1 | awk '/^time/{print $3}' Is there any other simple command that can be run from Korn Shell to display epoch time in solaris 5.10? (3 Replies)
Discussion started by: indianya
3 Replies

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

3. Shell Programming and Scripting

awk to calculate date and show data

data: hostcomment { host_name=myhost01 entry_type=1 comment_id=1 source=0 persistent=1 entry_time=1415723753 expires=0 expire_time=0 author=hpsm comment_data=IM0837437472 } program { modified_host_attributes=1 modified_service_attributes=1 enable_notifications=1... (20 Replies)
Discussion started by: SkySmart
20 Replies

4. Shell Programming and Scripting

Optimize shell script to run faster

data.file: contact { contact_name=royce-rolls modified_attributes=0 modified_host_attributes=0 modified_service_attributes=0 host_notification_period=24x7 service_notification_period=24x7 last_host_notification=0 last_service_notification=0 host_notifications_enabled=1... (8 Replies)
Discussion started by: SkySmart
8 Replies

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

6. OS X (Apple)

An Audio Function Generator...

Ok guys, gals and geeks... As from today I am starting to learn awk in earnest doing something totally different. I am going to create a pseudo-Audio_Function Generator centred around OSX 10.11.x minimum. The code below is a tester to see what the possibilities are. All waveforms will be... (11 Replies)
Discussion started by: wisecracker
11 Replies

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

8. Shell Programming and Scripting

Generating a POSIX random number?

Hi Guys and gals... As you know I am getting to grips with POSIX and hit this stumbling block. Generating two random numbers 0 to 255 POSIXly. Speed in not important hence the 'sleep 1' command. I have done a demo that works, but it sure is ugly! Is there a better way? #!/bin/sh # Random... (12 Replies)
Discussion started by: wisecracker
12 Replies

9. Shell Programming and Scripting

Time in seconds on AIX 4.3.2.0

Hi to everybody again i Need your help, i wasting hours but can't find a solutuin for my Problem. I am not an expert with AIX script programming. I have a csh script and i need the time in seconds but since i have an old AIX the Option -%s doesnot exist with the date command. I seach in Google... (13 Replies)
Discussion started by: Nadielosabra
13 Replies

10. Shell Programming and Scripting

Randomize columns in CSV file

Hi there, friends! Writing exams again! This time my wish would be to randomize certain columns in a csv file. Given a file containing records consisting of 3 columns tab-separated: A B C A B C A B C I would love to get the columns of each record in random order...separated by a tab as... (12 Replies)
Discussion started by: eldeingles
12 Replies

11. What is on Your Mind?

New Code Tags (Syntax Highlighting)

Hey, Just added a new UserCP option so you can change the code tags to look like the code tags in this example (turn this on and off): Note: I set the default to "SyntaxHighlighting" for debugging purposes. We can change the default back to the original code tags later. ... (36 Replies)
Discussion started by: Neo
36 Replies

12. Programming

Missing Logic Looping Through Switch Statement

Having trouble with the logic when looping over this switch case again: for (j = 0; data != 0; j++){ switch(data){ case 'c': output = ranit(r_brace_array); break; case 'h': output = ranit(pipe_array); break; ... (6 Replies)
Discussion started by: Azrael
6 Replies

13. HP-UX

awk command in hp UNIX subtract 30 days automatically from current date without date illegal option

current date command runs well awk -v t="$(date +%Y-%m-%d)" -F "'" '$1 < t' myname.dat subtract 30 days fails awk -v t="$(date --date="-30days" +%Y-%m-%d)" -F "'" '$1 < t' myname.dat awk command in hp unix subtract 30 days automatically from current date without date illegal option error... (20 Replies)
Discussion started by: kmarcus
20 Replies