Random value from array

    0

    1

    Jason Storey

    The code attempts to generate a random element from the list. It uses the Random class to generate a random number between 0 and the list's Count.

    public static T GetRandom<T>(this IList<T> list) =>
    list[Random.Range(0, list.Count)];
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.