# First time MATLAB is open Shuffle gives the same order

**URL:** <https://psychtoolbox.discourse.group/t/first-time-matlab-is-open-shuffle-gives-the-same-order/5205>\
**Category:** Programming Help\
**Created:** [December 5, 2023, 8:15pm UTC](https://psychtoolbox.discourse.group/t/first-time-matlab-is-open-shuffle-gives-the-same-order/5205 "2023-12-05T20:15:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![greening](https://avatars.discourse-cdn.com/v4/letter/g/a9a28c/32.png) [@greening](https://psychtoolbox.discourse.group/u/greening)\
**Post date:** [December 5, 2023, 8:15pm UTC](https://psychtoolbox.discourse.group/t/first-time-matlab-is-open-shuffle-gives-the-same-order/5205/1 "2023-12-05T20:15:15Z")

</div>

Hi,

We are trying to use Shuffle to randomize our trial order. But when we open MATLAB we are getting the same trial order, as if the randomizer is seeded. But from what I can see, there is no seeding option, and there is no way to turn of this seeding. We can replicate this using

```auto
randvec(1:10,1) = 1:10; Shuffle(randvec)

```

And restarting Matlab each time.

Could you help provide a suggestion on making this truly a random shuffle?  
Thanks

---

<div class="post-metadata">

**Author:** ![xiangrui](https://avatars.discourse-cdn.com/v4/letter/x/ec9cab/32.png) [@xiangrui](https://psychtoolbox.discourse.group/u/xiangrui)\
**Post date:** [December 5, 2023, 8:35pm UTC](https://psychtoolbox.discourse.group/t/first-time-matlab-is-open-shuffle-gives-the-same-order/5205/2 "2023-12-05T20:35:43Z")

</div>

That is the design by Matlab.  
When you want random seed, you will need to set random seed before you use any of those rand\* functions. PTB has

```
ClockRandSeed

```

---

<div class="post-metadata">

**Author:** ![keith](https://avatars.discourse-cdn.com/v4/letter/k/f05b48/32.png) [@keith](https://psychtoolbox.discourse.group/u/keith)\
**Post date:** [December 5, 2023, 8:37pm UTC](https://psychtoolbox.discourse.group/t/first-time-matlab-is-open-shuffle-gives-the-same-order/5205/3 "2023-12-05T20:37:56Z")

</div>

You need to choose a random seed if you want to have different random sequences, otherwise the default seed is zero. You want to call the function rng(“shuffle”) once at the top of your script.

keith

---

<div class="post-metadata">

**Author:** ![mariokleiner](https://avatars.discourse-cdn.com/v4/letter/m/13edae/32.png) [@mariokleiner](https://psychtoolbox.discourse.group/u/mariokleiner)\
**Post date:** [December 11, 2023, 7:10pm UTC](https://psychtoolbox.discourse.group/t/first-time-matlab-is-open-shuffle-gives-the-same-order/5205/4 "2023-12-11T19:10:05Z")

</div>

`ClockRandSeed` is the recommended choice over `rng('shuffle')` as it will call `rng('shuffle')` internally if supported, but fall back to other good solutions if the given Matlab or Octave version does not support the former.
