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)
Check Out this Related Man Page
rand(3C)rand(3C)NAME
rand(), rand_r(), srand() - simple random-number generator
SYNOPSIS DESCRIPTION
uses a multiplicative, congruential, random-number generator with period 2^32 that returns successive pseudo-random numbers in the range
from 0 to 2^15-1.
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.
returns a random number at the address pointed to by the randval parameter. The seed parameter can be set at any time to start the random-
number generator at an arbitrary point.
Note
The spectral properties of leave a great deal to be desired. provides a much better, though more elaborate, random-number generator (see
drand48(3C)).
RETURN VALUE
If seed or randval is NULL, returns 0. Otherwise, returns a psuedo-random integer.
EXAMPLES
The following:
int x, y;
srand(10);
x = rand();
y = rand();
would produce the same results as:
int x, y, s = 10;
x=rand_r(&s);
y=rand_r(&s);
WARNINGS
Users of should note that rand_r() now conforms with POSIX.1c. The old prototype of is supported for compatibility with existing DCE
applications only.
SEE ALSO drand48(3C), random(3M), thread_safety(5), random(7).
STANDARDS CONFORMANCE rand(3C)
Hello, I am very new to shell scripting. This problem seems quite easy so it should be quite easy (I hope ^^)
I want to get a random file from a directory. this file will be in one subdirectory, and it will contain spaces.
code I have got so far:
N=find ./*/*.jpg | wc -l
((N=RANDOM%N))
... (6 Replies)
can any one tell me how to create integer random no between 10 to 40 in C language.When i m using random() or rand() functions they r creting some
long int which is not required (5 Replies)
Hi,
I am currently trying to generate multiple random numbers in C for different variable:-
die1=1+(rand()%5);
die2=1+(rand()%5);
die3=1+(rand()%5);
die4=1+(rand()%5);
But I need to contrain the total of die1, die2,die3 and die4 to be 5 as well. If i insert die1+die2+die3+die4=5, i do... (6 Replies)
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)
I need a sed line that will take STDM111 and change it to STDM161
the STDM will always be constant but the 3 numbers after will be random, I just need it to always replace the middle number with 6 regardless of what the numbers are. (8 Replies)
Hi,
I have a file with the following content:
---------
a 3242 tc_5 gdfg4
random text
a 3242 tc_6 gdfg4
random text
a 3242 tc_7 gdfg4
random text
a 3242 tc_4 gdfg4
---------
I want to replace the lines containing tc_? (tc_5, tc_6 etc. even with unknown numbers) with the found... (5 Replies)
Hi,
I need a script that will generate a set of random strings in sequence, with the ability to predetermine the length, quantity, and alphabet of individual string, and to use the outputs of earlier strings in the sequence to define the parameters of later strings. For examples, I might want... (5 Replies)
what types of methods and algorithms are used to track random number generators? I'm working on computer security, and I want to know all the different ways to track random number generators so I know what to counter (8 Replies)
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)
Hello All, I am stuck up in a program where the rand functions ends up giving all the same integers. Tried sleep, but the numbers turned out to be same... Can anyone help me out how to fix this issue ? I have called the srand once in the program, but I feel like when I call fork the child process... (5 Replies)
i want to generate a random number through a script, and even if anyone reads the script, they wont be able to figure out what the random number is. only the person who setup the script would know it.
something like this could work: random
the full thread is here:
... (13 Replies)
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)
Hi everyone
I just got my hands on a T5120 running Sol10. As far as I've read, the T2 chip has a built-in hardware number generator. My question is: how can I access it to get random numbers in either C or Fortran? I'm using Sun Studio 12.4.
I am currently trying to write an... (13 Replies)