petsc-3.7.3 2016-07-24
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
Index of all Sys routines
Table of Contents for all manual pages
Index of all manual pages

### Examples

src/sys/classes/random/examples/tutorials/ex1.c.html
src/sys/classes/random/examples/tutorials/ex2.c.html
src/ksp/ksp/examples/tutorials/ex11.c.html
src/ksp/ksp/examples/tutorials/ex11f.F.html