randomname icon indicating copy to clipboard operation
randomname copied to clipboard

feature: pass max length for resulting name

Open shaunc opened this issue 3 years ago • 2 comments

I would like to use names to label pattern recognition results, and would like to fit names into a fixed-width numpy recarray field. I can write a wrapper to repick until a name meets the length criteria, but would be nice if the api supported this functionality (and possibly more efficient if the lists themselves allowed drawing by length).

Thanks for this package!

shaunc avatar Jan 23 '22 01:01 shaunc

Hi thanks for the feature req!

I am open to supporting something like this or at least make it easier to design and apply your own constraints. I have some changes that refactors the core into something more modular so it may make it easier for end users to make a change like this. But I just need to find time to finish and push them up.

Do you think you could elaborate on how you'd like the more efficient way to work? Because I can think of a few ways of doing it, but they have implications on how the output would look.

For example,

words = []
maxlen = 12
for cat in ['a/', 'n/']:
    w = sample_word(cat, maxlen=maxlen)
    maxlen -= len(w)
    words.append(w)

Would cause only the later words to be constrained to be shorter. Maybe resampling the longest word could be a better way, but I'd like your insights. There's also more intelligent logic that could be done to deal with edge cases where the space of valid solutions is limited, but I'd like to keep this package pretty simple.

beasteers avatar Jan 24 '22 03:01 beasteers

Thanks for this package, @beasteers

I just learned about it and found myself having a similar requirement as @shaunc. For my use case, I care more about getting a fixed length than a max length, as I want this to make easier to understand some logs/console output. Of course, I can add my own wrapper, or pad with blanks.

xverges avatar Jan 31 '22 11:01 xverges