Skip to content

Function to pick random element from a list #453

@MadJlzz

Description

@MadJlzz

Not a while ago, I had the need to pick a random element of a slice in a gotemplate. Since I am using sprig for it's other nice functions, I was wondering if that's something that could be added?

In essence, I am personally using it like so:

{{ $myList := list 1 2 3 4 5 }}
# picks a random number from myList
{{ $myList | random }}

Pretty simple.
If that sounds interesting to add, I can work on that.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions