Skip to main content
`Ctrl`+`K`

# PetscRandomSetSeed

Sets the random seed. You MUST call `PetscRandomSeed()` after this call to have the new seed used.

## Synopsis

    #include "petscsys.h"
    PetscErrorCode PetscRandomSetSeed(PetscRandom r, PetscInt64 seed)

Not collective

## Input Parameters

- r - The random number generator context

- seed - The random seed

## Example Usage

          PetscRandomSetSeed(r,a positive integer);
          PetscRandomSeed(r);
          PetscRandomGetValue() will now start with the new seed.

          PetscRandomSeed(r) without a call to PetscRandomSetSeed() re-initializes
          the seed. The random numbers generated will be the same as before.

## See Also

`PetscRandom`, `PetscRandomCreate()`, `PetscRandomGetSeed()`, `PetscRandomSeed()`

## Level

intermediate

## Location

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

## Examples

src/ml/da/tutorials/ex2.c
src/snes/tutorials/ex12.c
src/ml/da/tutorials/ex3.c
src/ml/da/tutorials/ex4.c
src/ml/da/tutorials/ex1.c
src/ksp/ksp/tutorials/ex70.c

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