Re: Gaussian Distribution Using Dice
- Posted by Lewis Townsend <keroltarr at hotmail.com> Jul 31, 2004
- 471 views
ck, Here is my solution but it doesn't do any graffing. I think it is mathematically correct but it could be wrong. I just wrote it real quick. It prints up something that looks right to me.
include get.e function sum( sequence s ) atom a a = 0 for i = 1 to length( s ) do a+= s[i] end for return a end function constant NumOfDice = 3 constant NumOfSides = 6 constant MaximumRoll = NumOfDice * NumOfSides sequence chances, dice chances = repeat( 0, MaximumRoll ) dice = repeat( 1, NumOfDice ) integer roll for d = 1 to power( NumOfSides, NumOfDice ) do chances[sum(dice)] += 1 dice[1]+=1 for i = 1 to NumOfDice -1 do if dice[i] > NumOfSides then dice[i] = 1 dice[i+1] += 1 end if end for end for printf( 1, "The distobution of %d %d sided dice rolls:\n", {NumOfDice,NumOfSides} ) puts( 1, "Value\tChance\n" ) for i = 1 to length( chances ) do printf(1, "%d\t%d\n", i&chances[i] ) end for if wait_key() then end if
Below lies the signature of Lewis Townsend Lewy T