randBetween(low,high) ??

Discuss macro implementations, ask for macro help (to share your creations, see User Creations, probably either Campaign Frameworks or Drop-in Resources).

Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice

Post Reply
User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

randBetween(low,high) ??

Post by wolph42 »

Its really been ages last time I asked a 'function' question on this forum, but here we go:

due to this topic: http://forums.rptools.net/viewtopic.php?f=3&t=26102 I was wondering whether there actually exists a function in the maptool function library that returns a random number between x and y (e.g. a random number ranging from 5 and 11)? I know you can easily build a function to emulate this

Code: Select all

[h:'<!-- randBetween(low, high):random number ranging from low to high  -->']
[h:assert(argCount()==2,"ERROR: randBetween requires exactly two (numeric) parameters",0)]
[h:macro.return = roll(1,arg(1)-arg(0)+1) + arg(0)-1] 
but I was wondering whether this function already exists and if not whether it should not be added to the feature list.

User avatar
aliasmask
RPTools Team
Posts: 9029
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: randBetween(low,high) ??

Post by aliasmask »

Code: Select all

[R: 1d11r5]
Not terribly efficient with large starting numbers, but does the same thing and preserves the range in the code. Your function would be better. Other languages usually don't have such a function either but does provide random and seed functions unlike MT. For example, rand would be a number between 0 and 1. Seed would restarted the random number with the seed value so you could get the same random numbers all things being equal.

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: randBetween(low,high) ??

Post by wolph42 »

aliasmask wrote:

Code: Select all

[R: 1d11r5]
Not terribly efficient with large starting numbers, but does the same thing and preserves the range in the code. Your function would be better. Other languages usually don't have such a function either but does provide random and seed functions unlike MT. For example, rand would be a number between 0 and 1. Seed would restarted the random number with the seed value so you could get the same random numbers all things being equal.
indeed. never new that existed and indeed not very efficient, but since its directly calculated in java instead of going through the parser first, it might certainly be more efficient for low numbers. Using that in 'randBetween instead' would probly look like:

Code: Select all

[h:macro.return = eval(strformat("1d%sr%s",arg(1), arg(5)))] 
which is doubtfully more efficient.

So If we would request something, would it be seed(), rand() and/or randbetween() or none of these as the interest is too low...? TBH everytime I look at [roll:] im surprised how it works. I expect it to be roll(low, high) but its roll(times, diceType) and I *do* recall having a need for a randBetween function one time or another and I probly solved it on the fly (like above). In all, especially when you're a *game* supporting system, you would expect some core randomizers...

User avatar
aliasmask
RPTools Team
Posts: 9029
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: randBetween(low,high) ??

Post by aliasmask »

Actually, I think xdyrz expression removes the chance of rolling below z. I tried this expecting a small delay (1d10000r10000) and it was instantaneous.

dorpond
RPTools Team
Posts: 5534
Joined: Thu Jun 01, 2006 2:05 pm
Location: Buffalo, NY

Re: randBetween(low,high) ??

Post by dorpond »

I would love to have the ability to do randbetween()

I actually have a need for that now. I am creating all the generic monster templates for D&D5 that work off the Monster Statistic by Challenge Rating chart in the DMG, and it clearly states that the creature will do 9-14 (one example) damage, so I really don't need to roll 'dice' to figure out how much damage it will do with said attack - just let me randbetween(9,14) and spit the output. Done.

So what other way can I go about this as we sit?
How to use my bundled artwork (MT1.3B60+): http://forums.rptools.net/viewtopic.php?f=8&t=11759

taustinoc
Dragon
Posts: 518
Joined: Mon Aug 03, 2015 6:30 pm

Re: randBetween(low,high) ??

Post by taustinoc »

If you want a flat distribution - equal chances of all results - 9-14 is exactly the same as 1d6+8.


User avatar
aliasmask
RPTools Team
Posts: 9029
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: randBetween(low,high) ??

Post by aliasmask »

As I mentioned above, you get the same results with xdyrz where x is 1, y is the high value and z is the low value.

dorpond
RPTools Team
Posts: 5534
Joined: Thu Jun 01, 2006 2:05 pm
Location: Buffalo, NY

Re: randBetween(low,high) ??

Post by dorpond »

aliasmask wrote:As I mentioned above, you get the same results with xdyrz where x is 1, y is the high value and z is the low value.
Ah yes, I missed that. Thank you, Aliasmask!
How to use my bundled artwork (MT1.3B60+): http://forums.rptools.net/viewtopic.php?f=8&t=11759

Post Reply

Return to “Macros”