andreasonny83 / unique-names-generator

Generate unique and memorable name strings
https://codesandbox.io/s/unique-names-generator-7fn9r
MIT License
590 stars 61 forks source link

Using Ethereum addresses as seed issue #56

Open alexishecf opened 2 years ago

alexishecf commented 2 years ago

Hello,

I am using your package with Ethereum addresses as a seed (with the 0x prefix removed) and the dictionaries adjectives and animals. It appears that some adjectives and animals will never (or extremely rarely?) be used when calling uniqueNamesGenerator with the address as a seed but others will be very often.

For instance, if I want to generate a vanity name (i.e. I want my name generated from the ETH address to contains whale, see script below)

The expected outcome is that every time I run the vanity name generator, I get an {adjective} + Whale nickname, where {adjective} is one of the many adjectives in the dictionary.

But in reality, it will very often be the same adjective, here is a sample of 100 generated names that includes Whale (each one was generated using a different ETH address):

InternalWhale
RemarkableWhale
InternalWhale
InternalWhale
InternalWhale
InternalWhale
InternalWhale
RemarkableWhale
InternalWhale
RemarkableWhale
DigitalWhale
RemarkableWhale
InternalWhale
RemarkableWhale
InternalWhale
DigitalWhale
InternalWhale
RemarkableWhale
InternalWhale
InternalWhale
RemarkableWhale
RemarkableWhale
InternalWhale
RemarkableWhale
DigitalWhale
InternalWhale
InternalWhale
InternalWhale
InternalWhale
RemarkableWhale
RemarkableWhale
InternalWhale
RemarkableWhale
DigitalWhale
RemarkableWhale
RemarkableWhale
DigitalWhale
DigitalWhale
RemarkableWhale
InternalWhale
InternalWhale
RemarkableWhale
InternalWhale
RemarkableWhale
RemarkableWhale
InternalWhale
RemarkableWhale
InternalWhale
RemarkableWhale
InternalWhale
InternalWhale
InternalWhale
RemarkableWhale
DigitalWhale
InternalWhale
InternalWhale
RemarkableWhale
RemarkableWhale
RemarkableWhale
InternalWhale
InternalWhale
RemarkableWhale
RemarkableWhale
InternalWhale
InternalWhale
InternalWhale
RemarkableWhale
RemarkableWhale
InternalWhale
InternalWhale
RemarkableWhale
RemarkableWhale
RemarkableWhale
InternalWhale
DigitalWhale
DigitalWhale
RemarkableWhale
RemarkableWhale
InternalWhale
InternalWhale
RemarkableWhale
RemarkableWhale
RemarkableWhale
RemarkableWhale
DigitalWhale
RemarkableWhale
RemarkableWhale
InternalWhale
RemarkableWhale
RemarkableWhale
RemarkableWhale
RemarkableWhale
RemarkableWhale
RemarkableWhale
RemarkableWhale
RemarkableWhale
InternalWhale
InternalWhale
RemarkableWhale
InternalWhale

I think there is an issue in how the seed is generated from a string, perhaps it is too big? Also, if tou try using a VERY big number as a seed, you will always end up with the same name, so I think there is an issue with the seed.

Script to generate vanity names:

const { uniqueNamesGenerator, adjectives, colors, animals } = require('unique-names-generator');
var Web3 = require('web3');

const arg = process.argv[2];

const web3 = new Web3();

if (!arg) {
  const readline = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout,
  });
  readline.question('Vanity name should include: ', (contains) => {
    console.log(`Searching name with ${contains}!`);
    readline.close();

    generateVanityName(contains);
  });
} else {
  console.log(`Searching name with ${arg}!`);
  generateVanityName(arg);
}

function generateNameFromAddress(address) {
  const customConfig = {
    dictionaries: [adjectives, animals],
    separator: '',
    length: 2,
    seed: address,
    style: 'capital',
  };

  return uniqueNamesGenerator(customConfig);
}

function generateVanityName(contains) {
  let account;
  let name;
  do {
    account = web3.eth.accounts.create();
    name = generateNameFromAddress(account.address.replace('0x', ''));
  } while (!name || !name.toLowerCase().includes(contains.toLowerCase()));

  console.log(account);
  console.log(name);
  return;
}
misterboe commented 2 years ago

I also have a problem that seems to be similar. I use as seed ID's from html elements. However, it happens that different seeds lead to the same names.

like: id__square-red-ocelot

seed:          w-node-aaa2dd9a-d07e-f025-8e3a-d68f7302a969-7302a968
uniqueName:    id__silly-emerald-shrimp
----------------------------
seed:          w-node-aaa2dd9a-d07e-f025-8e3a-d68f7302a96b-7302a968
uniqueName:    id__ethnic-gold-caribou
----------------------------
seed:          w-node-aaa2dd9a-d07e-f025-8e3a-d68f7302a970-7302a968
uniqueName:    id__hot-tan-blackbird
----------------------------
seed:          w-node-_1eb647e8-2264-3644-e5c7-c6b89ffc5d1b-9ffc5d1a
uniqueName:    id__wittering-turquoise-turkey
----------------------------
seed:          w-node-_1eb647e8-2264-3644-e5c7-c6b89ffc5d1d-9ffc5d1a
uniqueName:    id__selfish-tan-sole
----------------------------
seed:          w-node-_1eb647e8-2264-3644-e5c7-c6b89ffc5d1f-9ffc5d1a
uniqueName:    id__extraordinary-beige-moth
----------------------------
seed:          w-node-_1eb647e8-2264-3644-e5c7-c6b89ffc5d26-9ffc5d1a
uniqueName:    id__cheap-copper-silverfish
----------------------------
seed:          w-node-_9fe443dc-e2f2-401c-e8da-697ef6821c29-f6821c28
uniqueName:    id__high-orange-sturgeon
----------------------------
seed:          w-node-_9fe443dc-e2f2-401c-e8da-697ef6821c2b-f6821c28
uniqueName:    id__interim-teal-cuckoo
----------------------------
seed:          w-node-_9fe443dc-e2f2-401c-e8da-697ef6821c2d-f6821c28
uniqueName:    id__fashionable-green-hoverfly
----------------------------
>> seed:          w-node-_9fe443dc-e2f2-401c-e8da-697ef6821c34-f6821c28
>> uniqueName:    id__square-red-ocelot
----------------------------
seed:          w-node-_17b33b5a-7885-2683-d59b-db6f5cf1c829-5cf1c828
uniqueName:    id__yearling-lavender-toucan
----------------------------
>> seed:          w-node-_17b33b5a-7885-2683-d59b-db6f5cf1c82b-5cf1c828
>> uniqueName:    id__square-red-ocelot
----------------------------
seed:          w-node-_17b33b5a-7885-2683-d59b-db6f5cf1c832-5cf1c828
uniqueName:    id__skinny-sapphire-pheasant
----------------------------
seed:          w-node-e3589836-a859-3f95-bfd0-ed7b002df5a6-002df5a5
uniqueName:    id__spicy-red-mole
----------------------------
seed:          w-node-e3589836-a859-3f95-bfd0-ed7b002df5ad-002df5a5
uniqueName:    id__likely-copper-manatee
----------------------------
seed:          w-node-e3589836-a859-3f95-bfd0-ed7b002df5af-002df5a5
uniqueName:    id__detailed-gray-hedgehog
----------------------------
seed:          w-node-e3589836-a859-3f95-bfd0-ed7b002df5b2-002df5a5
uniqueName:    id__fast-coral-rook
----------------------------
seed:          w-node-e3589836-a859-3f95-bfd0-ed7b002df5b5-002df5a5
uniqueName:    id__spicy-red-mole
----------------------------
seed:          w-node-e3589836-a859-3f95-bfd0-ed7b002df5b8-002df5a5
uniqueName:    id__nosy-violet-antelope
----------------------------
seed:          w-node-f3f6141e-0b56-d993-c70f-ef7317377454-17377453
uniqueName:    id__immediate-amethyst-mammal
----------------------------
seed:          w-node-f3f6141e-0b56-d993-c70f-ef731737745b-17377453
uniqueName:    id__rainy-azure-scorpion
----------------------------
seed:          w-node-bdfbe371-20ef-f282-4550-e9b9c955c474-c955c473
uniqueName:    id__unable-blush-quokka
----------------------------
seed:          w-node-bdfbe371-20ef-f282-4550-e9b9c955c47b-c955c473
uniqueName:    id__efficient-coral-chickadee
----------------------------
seed:          w-node-bdfbe371-20ef-f282-4550-e9b9c955c47d-c955c473
uniqueName:    id__electronic-maroon-crocodile
----------------------------
seed:          w-node-bdfbe371-20ef-f282-4550-e9b9c955c499-c955c473
uniqueName:    id__skinny-plum-xerinae
----------------------------
seed:          w-node-bdfbe371-20ef-f282-4550-e9b9c955c49b-c955c473
uniqueName:    id__electronic-maroon-crocodile
----------------------------

Code for generation:

const randomName =
  "id__" +
  uniqueNamesGenerator({
    dictionaries: [adjectives, colors, animals],
    separator: "-",
    length: 3,
    seed: divID,
  });
carleryd commented 3 months ago

There's a solution outlined here https://github.com/andreasonny83/unique-names-generator/issues/79

Currently, I solved this issue by using stringToSeed function, simply convert string to number, and the issue is gone.

I'm not 100% sure if it solves the issue completely, but it does resolve the duplicate mentioned above by @misterboe where these two generate the same outputs

seed:          w-node-bdfbe371-20ef-f282-4550-e9b9c955c47d-c955c473
uniqueName:    id__electronic-maroon-crocodile
----------------------------
seed:          w-node-bdfbe371-20ef-f282-4550-e9b9c955c49b-c955c473
uniqueName:    id__electronic-maroon-crocodile

My testing

> hashCode('w-node-bdfbe371-20ef-f282-4550-e9b9c955c47d-c955c473')
-1513594101
> hashCode('w-node-bdfbe371-20ef-f282-4550-e9b9c955c49b-c955c473')
-419502513
> uniqueNamesGenerator({ dictionaries: [adjectives, colors, animals], separator: '', seed: -1513594101, style: 'capital' })
'PromisingTealSilverfish'
> uniqueNamesGenerator({ dictionaries: [adjectives, colors, animals], separator: '', seed: -419502513, style: 'capital' })
'MildMoccasinBee'

using this implementation