// SPDX-License-Identifier: MIT // Copyright (c) 2026 Incoprea // Chance of exactly k successes // Not compiled or tested in-world // Setup: Place in a spare owned prim. Set TRIALS0..30, SUCCESSES0..TRIALS, and probability0..1. Touch to run; output is private to the owner. // Stop / restore: Disable/remove. No scene changes or external calls. // Notes: Assumes independent trials with constant success probability. This is an educational calculation, not a gambling system. // License: see LICENSE in this distribution. // Original Incoprea. MIT. integer TRIALS=10; integer SUCCESSES=3; float PROBABILITY=0.25; default { touch_start(integer detectedCount) { if(llDetectedKey(0)!=llGetOwner())return; if(TRIALS<0||TRIALS>30||SUCCESSES<0||SUCCESSES>TRIALS||PROBABILITY<0.0||PROBABILITY>1.0) { llOwnerSay("Invalid binomial inputs."); return; } if(PROBABILITY==0.0) { llOwnerSay("Probability="+(string)(SUCCESSES==0)); return; } if(PROBABILITY==1.0) { llOwnerSay("Probability="+(string)(SUCCESSES==TRIALS)); return; } float choose=1.0; integer k=SUCCESSES; if(k>TRIALS-k)k=TRIALS-k; integer i; for(i=1;i<=k;++i)choose*=((float)(TRIALS-k+i)/(float)i); float result=choose*llPow(PROBABILITY,(float)SUCCESSES)*llPow(1.0-PROBABILITY,(float)(TRIALS-SUCCESSES)); llOwnerSay("Probability="+(string)result); } }