Create Random team names for projects

Médéric Burlet - Mar 22 '22 - - Dev Community

Introduction

Here at Pixium Digital we often need to create sets of random usernames or team names.

This is either due to bench-marking with a need to simulate individuals groups or users.

Or for a need to anonymize leader-boards in various applications. This can be due to the fact that some applications have big firms as client that they want to keep anonymous hence we generate a random team or group name that can be displayed publicly without risking information leakage.

leaderboard

For this we have decided to build a small library that we can re-use to help us generate this content easily.

Basics

We first started to create a list of various information we would need. This includes adjectives, nouns, gamertags, colors, extended colors.

You find the more detailed list here:

https://github.com/pixiumdigital/random-namer/tree/master/src/data


We then wanted to create the possibility to add an ID at the end of the random generated content (discord like) so we could have a result like this:

  • myC00lUsername#3948
  • thundering-memory#8682

For this we used a little trick of Math.random()

/**
 * Generates a random ID (discord style)
 * @returns string
 */
export const randomId = () => {
    return Math.random().toString().substring(2, 6)
}
Enter fullscreen mode Exit fullscreen mode

Formats

Most of the random lists will be in the following format string[] however there will be specifications. For example teams will be composed in this format:

adjective-noun
Enter fullscreen mode Exit fullscreen mode

For example:

[
    'icy-dinosaurs',
    'mighty-scarecrow',
    'aquatic-squirrels',
    'defiant-camp',
    'natural-memory'
]
Enter fullscreen mode Exit fullscreen mode

Then we have the Extended Colors which are of the following format:

interface ExtendedColor {
    id: string
    name: string
    hex: string
    r: number
    g: number
    b: number
}
Enter fullscreen mode Exit fullscreen mode

Usage

To use the library you simply need to do the following:

yarn install @pixium-digital/random-namer
Enter fullscreen mode Exit fullscreen mode

Then you can use it like this:

import { RandomNamer, RandomType } from "@pixium-digital/random-namer"

const list = RandomNamer(RandomType.TEAM, { toGenerate: 3, allUnique: true, addId: true })
// ['voiceless-sea#4457', 'delicate-star#6563', 'even-nest#9988']

const list = RandomNamer(RandomType.GAMERTAG, { toGenerate: 2 })
// ['The Best Yoda', 'I_Cant_Play']
Enter fullscreen mode Exit fullscreen mode

Link

GitHub logo pixiumdigital / random-namer

Simple random name generator for various utilities

Random Namer

This project aims to simply provide random usernames, team names, gamertags, adjectives, colors to use in testing data.

Installation

yarn install @pixium-digital/random-namer
Enter fullscreen mode Exit fullscreen mode

Usage

import { RandomNamer, RandomType } from "@pixium-digital/random-namer"
const list = RandomNamer(RandomType.TEAM, { toGenerate: 3, allUnique: true, addId: true })
// ['voiceless-sea#4457', 'delicate-star#6563', 'even-nest#9988']

const list = RandomNamer(RandomType.GAMERTAG, { toGenerate: 2 })
// ['The Best Yoda', 'I_Cant_Play']
Enter fullscreen mode Exit fullscreen mode

Here is the list of random types that can be passed:

export enum RandomType {
    ADJECTIVE,
    COLOR,
    EXTENDED_COLOR,
    GAMERTAG,
    NOUN,
    TEAM,
}
Enter fullscreen mode Exit fullscreen mode

Here are the parameters available to pass to the function

{
    toGenerate: number // Number of items to generate
    allUnique?: boolean // Should the generated items be unique?
    addId?: boolean //
Enter fullscreen mode Exit fullscreen mode

Pixium Digital - Shaping your project with technology and innovation
https://pixiumdigital.com
https://github.com/pixiumdigital

. . . . . . . . . . . . . . . . . . .
Terabox Video Player