Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

How can I simulate a diceroll up to 12 but exclude it being able to land on 1-6

Hi Folks,


Im using this code to simulate a diceroll.

(set: $diceroll = Math.ceil(Math.random()*12))

I want to be able to set it so it will roll up to 12 like it does here but will not be able to land on numbers 1-6

if anyone can help i'd be really grateful, thanks!

Comments

  • edited May 2015
    You could setup an if statement to take care of it:
    (if: $diceroll <= 6)
    [
    (set: $diceroll to 0)
    ]
    
    Or set $diceroll to whatever, of course. ;)

    Tim
  • In general, something like the follow (otherwise you're buggering your distribution):
    (set: $diceroll = Math.floor(Math.random() * (MAX - MIN + 1)) + MIN)
    
    In your case, that would be (assuming you want a range of 7–12, inclusive):
    (set: $diceroll = Math.floor(Math.random() * (12 - 7 + 1)) + 7)
    
  • Although, thinking about this further, couldn’t you just do something like:
    (set: $diceroll to random(7,12))
    
    Why is rolling 1-12 important in this case?
  • Is the random() function available in Harlowe? If so, then simply use that (it should be functionally equivalent to my previous example code, if not exactly so).
  • Yes, it is.
  • So what are you trying to simulate?

    6 + d6
    rigged d12 - use 6 + d6 for an even distribution
    rigged 2d6 - this is somewhat harder as 7 should be more common than 12

    Try generating 0 to 20 and looking it up in this array:
    [ 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 9, 9, 9, 9, 10, 10, 10, 11, 11, 12 ]
    
Sign In or Register to comment.