Ad
  • Custom User Avatar

    This is JavaScript, and indeed, 7 is not in [2,0,0,1].

    This is by design. There is no issue. ( It's a feature, not a bug :)

  • Custom User Avatar

    I'm not sure which part this belongs to. Could you please specify the test case in which this occurs and the language you're using? I will then do my best to fix any existing issues. (Also note that the JavaScript version is fairly new.)

  • Custom User Avatar

    Try it yourself:

    function one_two() { return 1 + Math.random() * 2 | 0}
    
    let counter = {};
    for(let i=100000; i>0; --i) {
        value = one_two_three();
        if(!counter[value]) counter[value] = 0;
        counter[value]++;
    }
    
    console.log(counter);
    

    I should exdend test cases.

  • Custom User Avatar

    It valid for any random function with uniform distribution that return three elements.

    For example P(11) ≈ P(12) ≈ P(13) ≈ P(21) ≈ P(22) ≈ P(23) ≈ P(31) ≈ P(32) ≈ P(33) ≈ (1 / 3)**2 ≈ 0.11111111111
    Same for strings with length 3, 4 and so on

  • Custom User Avatar

    Do you passed test with consecutive 1's 2's 3's?
    Try to generate 60k length string and measure probability to find same length combinations, will it equal expected probability?

    P(any combination with length N) ≈ (1 / 3)**N