PetscRandomCreate

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

Synopsis

#include "petscsys.h" 
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() that are uniformly distributed over [0,1). The user can shift and stretch this interval by calling PetscRandomSetInterval().

Currently three types of random numbers are supported. These types are 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);

See Also

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

Level:intermediate
Location:
src/sys/src/utils/random.c
Index of all Sys routines
Table of Contents for all manual pages
Index of all manual pages

Examples

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