Random function giving same results each time?

Hi - I’ve created a script that casts a random episode of a TV show (stored locally). However, every time I activate the script, I seem to get the same episodes playing.

They’re random in the sense of the episodes being played (34, 12, 7 etc.) but the same random sequence plays every time.

The relevant piece of code is:

http://ipaddress/local/media/HeyDuggeeS01/{{range(1,53)|random}}.mp4’

Is this just a limit of the random function? Or am I missing something?

I just tested that exact code in the template editor and it works as expected for me.

Post your complete script.

alias: Hey Duggee
sequence:
  - service: media_player.play_media
    data:
      media_content_type: video
      media_content_id: >-
        http://ipaddress/local/media/HeyDuggeeS01/{{range(1,53)|random}}.mp4
    target:
      entity_id: media_player.chromecastultra5316
  - wait_for_trigger:
      - platform: state
        entity_id:
          - media_player.chromecastultra5316
        to: idle
        id: Idle
      - platform: state
        entity_id:
          - media_player.chromecastultra5316
        to: "off"
        id: "Off"
    continue_on_timeout: false
  - choose:
      - conditions:
          - condition: template
            value_template: "{{ wait.trigger.id == 'Idle' }}"
        sequence:
          - service: script.turn_on
            data: {}
            target:
              entity_id: script.duggee
      - conditions:
          - condition: template
            value_template: "{{ wait.trigger.id == 'Off' }}"
        sequence:
          - stop: ""
mode: single
icon: mdi:youtube-tv

The other script it calls is an exact replica (to get around not being able to call this script to play another episode as this script wouldn’t be finished)

As finity said - it works in the template editor, so wonder if it being a script is having a weird effect? I’m now also wondering if I’m going mad and have just seen too much Hey Duggee so every episode feels like its just been on - I’ll properly note down which episodes are running over the next day or so just to make sure!