Sponsored Content
Full Discussion: rand()
Top Forums Programming rand() Post 28035 by Perderabo on Wednesday 11th of September 2002 01:37:44 PM
Old 09-11-2002
The man page for rand says that it is a "multiplicative congruential" random number generator. That algorithm yields roughly a uniform distribution, but it's a lousy implementation of a lousy algorithm. It certainly does not produce anything at all like a normal distribution.

You should also have a function called drand48 which is a "linear congruential" random number generator. This also yields a uniform distribution, but the algorithm and implementation are much better than rand.

rand really should not be used in new code.

But unix doesn't have random number generators for other distributions. If you need a normal distribution maybe you can find some freeware by searching on google.

Also, you may want to read "The Art of Computer Programming Volume 2 Seminumerical Algorithms" by Donald Knuth. It shows how to transform uniform random numbers into random numbers with other distributions including normal.
 

We Also Found This Discussion For You

1. Programming

fork and rand()

Hi, I want build 10 processus with fork and that each processus write a value betwen 0 and 9 , but each processus send the same value . So my code ,you can compile and try . #include <time.h> #include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <sys/ipc.h> ... (7 Replies)
Discussion started by: carton99
7 Replies
slarnv.f(3)							      LAPACK							       slarnv.f(3)

NAME
slarnv.f - SYNOPSIS
Functions/Subroutines subroutine slarnv (IDIST, ISEED, N, X) SLARNV Function/Subroutine Documentation subroutine slarnv (integerIDIST, integer, dimension( 4 )ISEED, integerN, real, dimension( * )X) SLARNV Purpose: SLARNV returns a vector of n random real numbers from a uniform or normal distribution. Parameters: IDIST IDIST is INTEGER Specifies the distribution of the random numbers: = 1: uniform (0,1) = 2: uniform (-1,1) = 3: normal (0,1) ISEED ISEED is INTEGER array, dimension (4) On entry, the seed of the random number generator; the array elements must be between 0 and 4095, and ISEED(4) must be odd. On exit, the seed is updated. N N is INTEGER The number of random numbers to be generated. X X is REAL array, dimension (N) The generated random numbers. Author: Univ. of Tennessee Univ. of California Berkeley Univ. of Colorado Denver NAG Ltd. Date: November 2011 Further Details: This routine calls the auxiliary routine SLARUV to generate random real numbers from a uniform (0,1) distribution, in batches of up to 128 using vectorisable code. The Box-Muller method is used to transform numbers from a uniform to a normal distribution. Definition at line 98 of file slarnv.f. Author Generated automatically by Doxygen for LAPACK from the source code. Version 3.4.1 Sun May 26 2013 slarnv.f(3)
All times are GMT -4. The time now is 06:39 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy