Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

rand(3) [v7 man page]

RAND(3) 						     Library Functions Manual							   RAND(3)

NAME
rand, srand - random number generator SYNOPSIS
srand(seed) int seed; rand( ) DESCRIPTION
Rand uses a multiplicative congruential random number generator with period 232 to return successive pseudo-random numbers in the range from 0 to 215-1. The generator is reinitialized by calling srand with 1 as argument. It can be set to a random starting point by calling srand with what- ever you like as argument. RAND(3)

Check Out this Related Man Page

rand(3UCB)					     SunOS/BSD Compatibility Library Functions						rand(3UCB)

NAME
rand, srand - simple random number generator SYNOPSIS
/usr/ucb/cc [ flag ... ] file ... int rand(); int srand(seed) unsigned seed; DESCRIPTION
rand() uses a multiplicative congruential random number generator with period 2^32 to return successive pseudo-random numbers in the range from 0 to 2^31 -1. srand() can be called at any time to reset the random-number generator to a random starting point. The generator is initially seeded with a value of 1. SEE ALSO
cc(1B), drand48(3C), rand(3C), random(3C) NOTES
Use of these interfaces should be restricted to only applications written on BSD platforms. Use of these interfaces with any of the system libraries or in multi-thread applications is unsupported. The spectral properties of rand() leave a great deal to be desired. drand48(3C) and random(3C) provide much better, though more elaborate, random-number generators. The low bits of the numbers generated are not very random; use the middle bits. In particular the lowest bit alternates between 0 and 1. SunOS 5.11 30 Oct 2007 rand(3UCB)
Man Page

15 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

randomization

I have two files: First file with 10 words, as follow: randomword1, randomword2, randomword3, randomword4, etc... Second File shell script. word=$(cat hangman_words | cut -d" " -f1) letters=$(echo $word | wc -c) letters=$(( $letters - 1 )) echo $letters echo $word The script... (13 Replies)
Discussion started by: keyvan
13 Replies

2. Shell Programming and Scripting

$RANDOM does not work inside a shell script

Hi folks I'm coding on Ubuntu 9.04 standard shell. I'm writing a script that needs to generate a random number at some point of its execution. When I do echo $RANDOMas a command inside shell, I clearly get some randomly generated number However when I do i=`$RANDOM` echo $ior even... (14 Replies)
Discussion started by: ksk
14 Replies

3. Programming

Question about erand48 usage

Hi, Following is the trimmed down version of the code I'm using to generate a set of random numbers using erand48 #include <stdio.h> #include <stdlib.h> #include <math.h> main() { unsigned short xsubi; xsubi=10; double r; int x; int i=0,... (14 Replies)
Discussion started by: santosh_sugur
14 Replies

4. Shell Programming and Scripting

Help with removal of spaces between operators and operands

Hi I'm trying to remove blank spaces in expressions and function calls.. Consider the following example printf ("Hello"); a = a + b; I'm trying to eliminate space in between the function name and the opening brace. And also eliminate space between operators and operands.. That is, I'm... (19 Replies)
Discussion started by: abk07
19 Replies

5. Shell Programming and Scripting

Shell script that runs a random shell script

Hi, im trying to make a shell script that basically runs a random shell script form a list of shell scripts i specify. Im not very good at writing shell scripts, and am new to linux. Thanks in advance :) (15 Replies)
Discussion started by: kylecn
15 Replies

6. Shell Programming and Scripting

Randomize letters

Hi, Is there a tool somewhat parallel to rev, but which randomizes instead of reverses? I've tried rl, but I can only get it to randomize words. I was hoping for something like this echo "hello" | ran leolh less simpler solutions are also welcome. Sorry if the question is... (21 Replies)
Discussion started by: jeppe83
21 Replies

7. Shell Programming and Scripting

Get 20% of lines in File randomly

Hello, This is my code: nb_lignes=`wc -l $1 | cut -d " " -f1` for i in $(seq $nb_lignes) do m=`head $1 -n $i | tail -1` //command done Please how can i change it to get Get 20% of lines in File randomly to apply "command" on each line ? 20% or 40% or 60 % (it's a parameter) Thank you. (15 Replies)
Discussion started by: chercheur857
15 Replies

8. Shell Programming and Scripting

Randomly selecting sequences and generating specific output files

I have two files containing hundreds of different sequences with the same Identifiers (ID-001, ID-002, etc.,), something like this: Infile1: ID-001 ATGGGAGCGGGGGCGTCTGCCTTGAGGGGAGAGAAGCTAGATACA ID-002 ATGGGAGCGGGGGCGTCTGTTTTGAGGGGAGAGAAGCTAGATACA ID-003... (18 Replies)
Discussion started by: Xterra
18 Replies

9. Shell Programming and Scripting

Random web page download wget script

Hi, I've been attempting to create a script that downloads web pages at random intervals to mimic typical user usage. However I'm struggling to link $url to the URL list and thus wget complains of a missing URL. Any ideas? Thanks #!/bin/sh #URL List url1="http://www.bbc.co.uk"... (14 Replies)
Discussion started by: shadyuk
14 Replies

10. UNIX for Advanced & Expert Users

UNIX script for making random numbers without repetition

Hello, I have a column which have 7200 numbers and I am deciding to pick up 1440 numbers randomly without any reputation? Could any one let me know which script in unix will be work for my case? Regards Sajjad (17 Replies)
Discussion started by: sajmar
17 Replies

11. Shell Programming and Scripting

Help with appending random sequence to huge CDR file

Hi, I am in a terrible emergency. I have multiple cdr files with line count >6000. I need to append |0| | | | | | | |random| to end of each line. The random number should never repeat. Please help with a shell script to process all cdr's in a directory with above requirement. (23 Replies)
Discussion started by: shiburnair
23 Replies

12. What is on Your Mind?

What brand is your primary computer?

A poll is added. Please vote and share your experiences. :b: If you select option: Other Brand then please post the brand name (22 Replies)
Discussion started by: Yoda
22 Replies

13. UNIX for Beginners Questions & Answers

Random letters

Hi there, first of all this is not homework...this is a new type of exercise for practicing vocabulary with my students. I have a file consisting of two columns, separated by a tab, each line consisting of a word and its definition, separated by a line break. What i need is to replace a... (15 Replies)
Discussion started by: eldeingles
15 Replies

14. Solaris

Help setting up a bhyve branded zone

So I started with following the example on the omnios page for bhyve (sorry, I can't provide the link because I'm a post shy of the 5 to give a URL): And found that in the end I was able to create a running bhyve zone, but accessing it via zlogin results in a blank console. I've tried Debian 9... (14 Replies)
Discussion started by: stratacast1
14 Replies

15. UNIX for Beginners Questions & Answers

Cant log in from external monitor on laptop with broken screen.

Hello. I am installing Kali Linux on a laptop with no monitor. The installation goes fine through the external monitor and I can see the GRUB menu on boot, but once it comes time to log in it acts like my non existant laptop screen is my main monitor to type my login info on while my external is... (14 Replies)
Discussion started by: debpleb293
14 Replies