PetscRandomCreate

Creates a context for generating random numbers, and initializes the random-number generator.

Synopsis

int PetscRandomCreate(MPI_Comm comm,PetscRandomType type,PetscRandom *r)
Collective on MPI_Comm

Input Parameters

comm - MPI communicator
type - the type of random numbers to be generated, usually RANDOM_DEFAULT

Output Parameter

r -the random number generator context

Notes

By default, we generate random numbers via srand48()/drand48() thatare uniformly distributed over [0,1). The user can shift and stretchthis interval by calling PetscRandomSetInterval(). Currently three types of random numbers are supported. These typesare equivalent when working with real numbers.
RANDOM_DEFAULT -both real and imaginary components are random
RANDOM_DEFAULT_REAL -real component is random; imaginary component is 0
RANDOM_DEFAULT_IMAGINARY -imaginary component is random; real component is 0

Use VecSetRandom() to set the elements of a vector to random numbers.

Example of Usage

      PetscRandomCreate(PETSC_COMM_SELF,RANDOM_DEFAULT,&r);
      PetscRandomGetValue(r,&value1);
      PetscRandomGetValue(r,&value2);
      PetscRandomGetValue(r,&value3);
      PetscRandomDestroy(r);

Keywords

random, create

See Also

PetscRandomGetValue(), PetscRandomSetInterval(), PetscRandomDestroy(), VecSetRandom()

Examples

src/sles/examples/tutorials/ex11f.F
src/sles/examples/tutorials/ex2f.F
src/sles/examples/tutorials/ex4.c
src/sles/examples/tutorials/ex2.c
src/sles/examples/tutorials/ex11.c

Location: src/sys/src/utilsrandom.c
System Index
Table of Contents