petsc-3.13.6 2020-09-29
Report Typos and Errors

PetscRandomGetValue

Generates a random number. Call this after first calling PetscRandomCreate().

Synopsis

#include "petscsys.h" 
PetscErrorCode  PetscRandomGetValue(PetscRandom r,PetscScalar *val)
Not Collective

Intput Parameter

r -the random number generator context

Output Parameter

val -the value

Notes

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

When PETSc is compiled for complex numbers this returns a complex number with random real and complex parts. Use PetscGetValueReal() to get a random real number.

To get a complex number with only a random real part, first call PetscRandomSetInterval() with a equal low and high imaginary part. Similarly to get a complex number with only a random imaginary part call PetscRandomSetInterval() with a equal low and high real part.

Example of Usage

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

See Also

PetscRandomCreate(), PetscRandomDestroy(), VecSetRandom(), PetscRandomGetValueReal()

Level

intermediate

Location

src/sys/classes/random/interface/random.c

Examples

src/sys/classes/random/tutorials/ex1.c.html
src/sys/classes/random/tutorials/ex2.c.html
src/vec/vec/utils/tagger/tutorials/ex1.c.html
src/mat/tutorials/ex2.c.html
src/dm/field/tutorials/ex1.c.html
src/ksp/ksp/tutorials/ex11.c.html
src/ksp/ksp/tutorials/ex11f.F90.html
src/tao/unconstrained/tutorials/spectraladjointassimilation.c.html

Implementations

PetscRandomGetValue_Rand in src/sys/classes/random/impls/rand/rand.c
PetscRandomGetValue_Rand48 in src/sys/classes/random/impls/rand48/rand48.c
PetscRandomGetValue_Rander48 in src/sys/classes/random/impls/rander48/rander48.c
PetscRandomGetValue_Random123 in src/sys/classes/random/impls/random123/random123.c
PetscRandomGetValue_Sprng in src/sys/classes/random/impls/sprng/sprng.c

Index of all Sys routines
Table of Contents for all manual pages
Index of all manual pages