[RFC] New way of dealing with random suffixes

Developer discussion regarding MapTool 1.4

Moderators: dorpond, trevor, Azhrei

Forum rules
Posting now open to all registered forum users.
Post Reply
d4rkAlf
Cave Troll
Posts: 35
Joined: Thu Apr 16, 2015 9:48 am

[RFC] New way of dealing with random suffixes

Post by d4rkAlf »

Hi!

I've mostly spent the last couple of days trying to familiarize myself with the code base. One thing that caught my eye that I didn't like was the way random suffixes were handled. While it's true that the old way was Big O(1) in the average case it was Big O(infinity) in the (theoretical) worst case.

I decided I wanted to solve it using the Fisher-Yates shuffle (http://en.wikipedia.org/wiki/Fisher-Yates_shuffle) since it's pretty much the classical solution for this problem domain. One thing kind of lead to another and I ended up writing a fairly elegant class to deal with it.

I would greatly appreciate some feedback from you guys on it. It currently only supports up to 256 different suffixes. I kind of figured "it ought to be enough for anybody". If the user tries to create a 257th token with a random suffix it simply shows an error and then loops around with a fresh set of numbers between 1 and 256. I don't know how to get the internationalization working in combination with the showError method so I could use a helping hand there. Comments?

https://github.com/DarkAlf/maptool/tree/randomsuffix

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

Re: [RFC] New way of dealing with random suffixes

Post by wolph42 »

"it ought to be enough for anybody".
actually you can safely assume its not. Especially if people start using the BoT and e.g. use the 'crowd control' function (aka 'zombie walk') a few 100 tokens will be used.

d4rkAlf
Cave Troll
Posts: 35
Joined: Thu Apr 16, 2015 9:48 am

Re: [RFC] New way of dealing with random suffixes

Post by d4rkAlf »

wolph42 wrote:
"it ought to be enough for anybody".
actually you can safely assume its not. Especially if people start using the BoT and e.g. use the 'crowd control' function (aka 'zombie walk') a few 100 tokens will be used.
Ok, cool. It won't be much trouble increasing the range of available values, but it might increase the memory consumption slightly. Thank you for your feedback.

User avatar
RPTroll
TheBard
Posts: 3159
Joined: Tue Mar 21, 2006 7:26 pm
Location: Austin, Tx
Contact:

Re: [RFC] New way of dealing with random suffixes

Post by RPTroll »

1024?
ImageImage ImageImageImageImage
Support RPTools by shopping
Image
Image

User avatar
Jagged
Great Wyrm
Posts: 1306
Joined: Mon Sep 15, 2008 9:27 am
Location: Bristol, UK

Re: [RFC] New way of dealing with random suffixes

Post by Jagged »

I don't want to sound negative but I am not sure we should implement something that we know causes an error, even if that error only occurs in very rare events.

User avatar
RPTroll
TheBard
Posts: 3159
Joined: Tue Mar 21, 2006 7:26 pm
Location: Austin, Tx
Contact:

Re: [RFC] New way of dealing with random suffixes

Post by RPTroll »

Could you make it so that when it runs out that it grabs the next set of numbers? Use 256 to start, once that is reached go up to 512, then bump to 768, the 1024, etc?
ImageImage ImageImageImageImage
Support RPTools by shopping
Image
Image

User avatar
JamzTheMan
Great Wyrm
Posts: 1872
Joined: Mon May 10, 2010 12:59 pm
Location: Chicagoland
Contact:

Re: [RFC] New way of dealing with random suffixes

Post by JamzTheMan »

RPTroll wrote:Could you make it so that when it runs out that it grabs the next set of numbers? Use 256 to start, once that is reached go up to 512, then bump to 768, the 1024, etc?
I'd prefer this as well. I would think if you had a counter, when running out the first 256, restarting the sequence and adding counter*256 to the next set would solve it?
-Jamz
____________________
Custom MapTool 1.4.x.x Fork: maptool.nerps.net
Custom TokenTool 2.0 Fork: tokentool.nerps.net
More information here: MapTool Nerps! Fork

d4rkAlf
Cave Troll
Posts: 35
Joined: Thu Apr 16, 2015 9:48 am

Re: [RFC] New way of dealing with random suffixes

Post by d4rkAlf »

JamzTheMan wrote:
RPTroll wrote:Could you make it so that when it runs out that it grabs the next set of numbers? Use 256 to start, once that is reached go up to 512, then bump to 768, the 1024, etc?
I'd prefer this as well. I would think if you had a counter, when running out the first 256, restarting the sequence and adding counter*256 to the next set would solve it?
Yeah, that's the plan. It would allow for up to 256*256 suffixes. While I'm at it I'm also going to implement a limit that adds the new set of suffixes before it runs out of the old ones.

User avatar
Jagged
Great Wyrm
Posts: 1306
Joined: Mon Sep 15, 2008 9:27 am
Location: Bristol, UK

Re: [RFC] New way of dealing with random suffixes

Post by Jagged »

Sounds great :)

d4rkAlf
Cave Troll
Posts: 35
Joined: Thu Apr 16, 2015 9:48 am

Re: [RFC] New way of dealing with random suffixes

Post by d4rkAlf »

Jagged wrote:I don't want to sound negative but I am not sure we should implement something that we know causes an error, even if that error only occurs in very rare events.
Well "error" is making it sound worse than it is. It would have been more of a warning so that the user knows that the program has run out of random numbers. Not that it matters any longer since we're not going down that route.

Post Reply

Return to “MapTool 1.4”