# PetscRandomGetValueReal
Generates a real random number.  Call this after first calling `PetscRandomCreate()`. 
## Synopsis
```
#include "petscsys.h" 
PetscErrorCode PetscRandomGetValueReal(PetscRandom r, PetscReal *val)
```
Not Collective


## Input Parameter

- ***r  -*** the random number generator context



## Output Parameter

- ***val -*** the value





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


## Example of Usage
```none
      PetscRandomCreate(PETSC_COMM_WORLD,&r);
      PetscRandomGetValueReal(r,&value1);
      PetscRandomGetValueReal(r,&value2);
      PetscRandomGetValueReal(r,&value3);
      PetscRandomDestroy(&r);
```



## See Also
 `PetscRandom`, `PetscRandomCreate()`, `PetscRandomDestroy()`, `VecSetRandom()`, `PetscRandomGetValue()`

## Level
intermediate

## Location
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/sys/classes/random/interface/random.c.html#PetscRandomGetValueReal">src/sys/classes/random/interface/random.c</A>

## Examples
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/dm/tutorials/swarm_ex3.c.html">src/dm/tutorials/swarm_ex3.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/dm/field/tutorials/ex1.c.html">src/dm/field/tutorials/ex1.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/tutorials/ex21.c.html">src/ksp/ksp/tutorials/ex21.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/tutorials/ex70.c.html">src/ksp/ksp/tutorials/ex70.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/snes/tutorials/ex12.c.html">src/snes/tutorials/ex12.c.html</A><BR>

## Implementations

<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/sys/classes/random/impls/rand/rand.c.html#PetscRandomGetValueReal_Rand">PetscRandomGetValueReal_Rand in src/sys/classes/random/impls/rand/rand.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/sys/classes/random/impls/rand48/rand48.c.html#PetscRandomGetValueReal_Rand48">PetscRandomGetValueReal_Rand48 in src/sys/classes/random/impls/rand48/rand48.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/sys/classes/random/impls/rander48/rander48.c.html#PetscRandomGetValueReal_Rander48">PetscRandomGetValueReal_Rander48 in src/sys/classes/random/impls/rander48/rander48.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/sys/classes/random/impls/random123/random123.c.html#PetscRandomGetValueReal_Random123">PetscRandomGetValueReal_Random123 in src/sys/classes/random/impls/random123/random123.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/sys/classes/random/impls/sprng/sprng.c.html#PetscRandomGetValueReal_Sprng">PetscRandomGetValueReal_Sprng in src/sys/classes/random/impls/sprng/sprng.c</A><BR>


---
[Edit on GitLab](https://gitlab.com/petsc/petsc/-/edit/release/src/sys/classes/random/interface/random.c)


[Index of all Sys routines](index.md)  
[Table of Contents for all manual pages](/docs/manualpages/index.md)  
[Index of all manual pages](/docs/manualpages/singleindex.md)  
