import type { IRandom } from "@thi.ng/random" ; import { SYSTEM } from "@thi.ng/random/system" ; import type { Reducer , Transducer } from "./api.js" ; import { compR } from "./compr.js" ; import { __iter } from "./iterator.js" ; /**
 * Transducer which only yields values with given `prob` probability
 * (0.0 .. 1.0 range). Supports custom PRNGs via
 *  {@link @thi.ng/random#IRandom} interface.
 *
 *  example param prob param src export function sample < T > ( prob ) ; export function sample < T > ( prob , rnd ) ; export function sample < T > ( prob , src ) ; export function sample < T > ( prob , rnd , src ) ; export function sample < T > ( ... args ) { const iter = __iter ( sample , args ) ; if ( iter ) { return iter ; } const prob = args [ 0 ] ; const rnd = args [ 1 ] || SYSTEM ; return ( rfn ) => { const r = rfn [ 2 ] ; return compR ( rfn , ( acc , x ) => rnd . float ( ) < prob ? r ( acc , x ) : acc ) ; } ; }