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
[RFC] New way of dealing with random suffixes
Moderators: dorpond, trevor, Azhrei
Forum rules
Posting now open to all registered forum users.
Posting now open to all registered forum users.
Re: [RFC] New way of dealing with random suffixes
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."it ought to be enough for anybody".
GETTING STARTED WITH MAPTOOLS - TUTORIALS, DOCS, VIDEOS, TOOLS, ETC
DISCORD (the new MT forum!)
My stuff
Excel Tools: Table and Light editors
MT Tools: Bag of Tricks: Tools for Maptool, Dungeon Builder I, Dungeon Builder II,onMouseOverEvent.
Frameworks: Dark Heresy, Rogue Trader, Deathwatch, Black Crusade, Only War, SET Card Game, RoboRally
Wiki: Debugging Tutorial, Speed Up Your Macros, Working With Two CODE Levels, Shortcut Keys, Avoiding Stack Overflow, READ THIS
DISCORD (the new MT forum!)
My stuff
Excel Tools: Table and Light editors
MT Tools: Bag of Tricks: Tools for Maptool, Dungeon Builder I, Dungeon Builder II,onMouseOverEvent.
Frameworks: Dark Heresy, Rogue Trader, Deathwatch, Black Crusade, Only War, SET Card Game, RoboRally
Wiki: Debugging Tutorial, Speed Up Your Macros, Working With Two CODE Levels, Shortcut Keys, Avoiding Stack Overflow, READ THIS
Re: [RFC] New way of dealing with random suffixes
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.wolph42 wrote: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."it ought to be enough for anybody".
Re: [RFC] New way of dealing with random suffixes
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.
Re: [RFC] New way of dealing with random suffixes
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?
- 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
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?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?
-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
____________________
Custom MapTool 1.4.x.x Fork: maptool.nerps.net
Custom TokenTool 2.0 Fork: tokentool.nerps.net
More information here: MapTool Nerps! Fork
Re: [RFC] New way of dealing with random suffixes
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.JamzTheMan wrote: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?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?
Re: [RFC] New way of dealing with random suffixes
Sounds great
Re: [RFC] New way of dealing with random suffixes
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.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.