The Daily Click ::. Forums ::. Klik Coding Help ::. Special dice simulation
 

Post Reply  Post Oekaki 
 

Posted By Message

Dave S.



Registered
  26/09/2003
Points
  924
18th May, 2005 at 15:54:39 -

What would be the easiest way to simulate a (non animated) dice throw, where the sides are not the usual numbers (one through to six) but made up of other combinations of numbers... say, 1,2,3,5,8,13, or 1,2,4,8,16,32.



 
n/a

David Newton (DavidN)

Invisible

Registered
  27/10/2002
Points
  8322

Honored Admin Alumnus
18th May, 2005 at 16:00:45 -

When the possibilities are based on an obvious pattern, such as the second one that you described, you could pick a random number and perform an expression on it - for your example, 2^random(6) would give those possibilities.

I can't think of a totally obvious way to simulate non-patterned numbers, but off the top of my bald head...

You could select a random number and then have a list of conditions reading "IF (the randomly chosen number) = 1 THEN (Display the real number mapped to it). In your first example (and starting from 1), If 5 is chosen then display 8, If 6 then 13.

A faster way would be to use a list, and have a number on each row of the list - then select a row of the list randomly and display the number that that row contains.

Image Edited by the Author.

 
http://www.davidn.co.nr - Games, music, living in America

AndyUK

Mascot Maniac

Registered
  01/08/2002
Points
  14586

Game of the Week WinnerSecond GOTW AwardHas Donated, Thank You!VIP Member
19th May, 2005 at 10:38:26 -

I would do what wong said about mapping a number to one of the possibilities. It would be easy to make two counters, 1 for random number (5)+1 and the other for the real outcome.

 
.

Dave S.



Registered
  26/09/2003
Points
  924
20th May, 2005 at 16:07:04 -

Mapping numbers did cross my mind but thought there may have been a more glamorous way of doing it. Anyway it works fine, thanks... Oragery.

 
n/a

X_Sheep

I had a custom rating before it was cool

Registered
  01/03/2004
Points
  1313

VIP MemberPicture Me This -Round 23- Winner!Dos Rules!
21st May, 2005 at 02:48:09 -

Arrays could help.

 
a/n

Kirby Smith

Resident Slacker

Registered
  18/05/2003
Points
  479

VIP Member360 OwnerWii OwnerThe Cake is a Lie
21st May, 2005 at 03:23:32 -

This probably won't work for all sequences, but it'll work for a lot of them.

Let's say you want to have a dice with the numbers 3, 5, 7, 9, 11, etc...

That could also be written as XsubN = 2n+1

So what you'd do is have a random (1 thru S) where S is the sides on the dice, and then apply that number to the formula for determining the actual value of the roll.

You'd have to play with your number sequences in order to make sure they can be defined by some sort of a pattern.

Don't know if that helped you at all, but it's something you might try.

 
XBL Gamertag: Rampant Mjolnir
   

Post Reply



 



Advertisement

Worth A Click