Jump to content

randomization code


crazysaint

Recommended Posts

i would like to come up with two codes in ASP that will

 

a) simulate the throeing of a dice: when run it should display the face value of the dice(between 1 and 6)

 

b)then also i would like to come up with another code  that shows that all faces have equal liklihood of being shown.(should throw it for about 6000 times). i know it has something to do with using a counter for eah face and increment as it wins.

Link to comment
Share on other sites

hmmm maybe  you should try an asp forum.

 

in php this may help (assumes you really want to do the 6000 throws)...


$throw = rand(1,6);
echo $throw;

$throwarr = array();
for($i = 0; $i < 6000; $i++)
{
$throwarr[] = rand(1,6);
}

$numbers = array_unique($throwarr);

$tally = array();
foreach ($numbers as $val)
{
$tally[$val] = count(array_keys($throwarr,$val));
}

print_r($tally);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.