Jump to content

weighted random number


tomdelonge

Recommended Posts

try

<?php

$array_of_pos = array(1,2,3,4,5);

for ($i=0;$i<10000;$i++){

foreach ($array_of_pos as $pos)

//create new value foreach positions

$tmp[$pos] = ($pos + 7) * rand();

asort($tmp);//sort new array

$tmp = array_flip($tmp);

$first = array_shift($tmp);//get 1st element

$out[]=$first; // put element for analise

}

$distribution = array_count_values($out);

ksort($distribution);

print_r($distribution);

?>[7php]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.