# How to get new random values at every run of a testset?

**URL:** <https://discourse.julialang.org/t/how-to-get-new-random-values-at-every-run-of-a-testset/25365>\
**Category:** General Usage\
**Created:** [June 17, 2019, 11:58am UTC](https://discourse.julialang.org/t/how-to-get-new-random-values-at-every-run-of-a-testset/25365 "2019-06-17T11:58:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tencnivel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tencnivel/32/8662_2.png) [@tencnivel](https://discourse.julialang.org/u/tencnivel)\
**Post date:** [June 17, 2019, 11:58am UTC](https://discourse.julialang.org/t/how-to-get-new-random-values-at-every-run-of-a-testset/25365/1 "2019-06-17T11:58:21Z")

</div>

Hello,

How can I have functions like `randstring()` generate new values at every run of a testset.  
For example, in the following test, I have to restart a julia session to get a different value from the previous execution.

```julia
using Test
using Random

@testset "Test random" begin
    println(randstring(5))
end

```

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [June 17, 2019, 12:14pm UTC](https://discourse.julialang.org/t/how-to-get-new-random-values-at-every-run-of-a-testset/25365/2 "2019-06-17T12:14:51Z")

</div>

From the `@testset` docs:

> Before the execution of the body of a @testset, there is an implicit call to Random.seed!(seed) where seed is the current seed of the global RNG. Moreover, after the  
> execution of the body, the state of the global RNG is restored to what it was before the @testset. This is meant to ease reproducibility in case of failure, and to allow  
> seamless re-arrangements of @testsets regardless of their side-effect on the global RNG state.

So the solution is to add a `Random.seed!()` call before the `@testset`.
