Random with probability

    0

    0

    anastasiia-tilikina

    The code generates a number between 1 and the numbers array's length.

    Shortcut: getrandom

    function generateRandomNum() {
      const numbers = [2, 2, 2, 2, 2, 2, 2, 2, 4, 4];
      const idx = Math.floor(Math.random() * numbers.length);
    
      return numbers[idx];
    }
    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.