第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

使用 Java 生成用戶名(字母數(shù)字字符串)

使用 Java 生成用戶名(字母數(shù)字字符串)

萬(wàn)千封印 2023-07-28 16:41:30
使用 Java 生成“有意義的”用戶名(字母數(shù)字字符串)的最有效方法是什么?用戶名格式如下:LastSamurai33DarkLord96FallenAngelIceQueenLadyPhantom666DarkSun感謝您的時(shí)間。
查看完整描述

4 回答

?
滄海一幻覺

TA貢獻(xiàn)1824條經(jīng)驗(yàn) 獲得超5個(gè)贊

您可以使用Java Faker生成各種隨機(jī)假數(shù)據(jù)。

這是一個(gè)例子

public static void main(String[] args) {

? ? ? ? Faker faker = new Faker();

? ? ? ? System.out.println(faker.superhero().prefix()+faker.name().firstName()+faker.address().buildingNumber());

? ? ? ? //MrSharon55747

? ? ? ? //IllustriousDock6698

? ? ? ? //CyborgDelilah207

? ? ? ? //GeneralAllison01931

? ? ? ? //RedWillard4366

? ? ? ? //TheJarvis71802

? ? }

Maven 依賴:


<dependency>

? ? <groupId>com.github.javafaker</groupId>

? ? <artifactId>javafaker</artifactId>

? ? <version>1.0.1</version>

</dependency>


查看完整回答
反對(duì) 回復(fù) 2023-07-28
?
揚(yáng)帆大魚

TA貢獻(xiàn)1799條經(jīng)驗(yàn) 獲得超9個(gè)贊

加載單獨(dú)的形容詞和名詞數(shù)組。要生成 uid,請(qǐng)隨機(jī)選擇其中一個(gè)。大寫。決定是否要附加一個(gè)整數(shù)以及應(yīng)該附加一個(gè)隨機(jī)數(shù)。連接并返回。

import java.io.IOException;

import java.nio.file.Files;

import java.nio.file.Path;

import java.nio.file.Paths;

import java.util.ArrayList;

import java.util.List;

import java.util.Random;

import java.util.stream.Stream;


public class UserIdGenerator {

? final List<String> adjectives = new ArrayList();

? final List<String> nouns = new ArrayList();

? final int minInt;

? final int maxInt;

? final Random random;


? public UserIdGenerator(Path adjectivesPath, Path nounsPath, int minInt, int maxInt)

? ? ? throws IOException {

? ? this.minInt = minInt;

? ? this.maxInt = maxInt;

? ? try (Stream<String> lines = Files.lines(adjectivesPath)) {

? ? ? lines.forEach(line -> adjectives.add(capitalize(line)));

? ? }

? ? try (Stream<String> lines = Files.lines(nounsPath)) {

? ? ? lines.forEach(line -> nouns.add(capitalize(line)));

? ? }

? ? this.random = new Random();

? }


? private static String capitalize(String s) {

? ? return Character.toUpperCase(s.charAt(0)) + s.substring(1).toLowerCase();

? }


? public String generate() {

? ? StringBuilder sb = new StringBuilder()

? ? ? ? .append(adjectives.get(random.nextInt(adjectives.size())))

? ? ? ? .append(nouns.get(random.nextInt(nouns.size())));

? ? int i = random.nextInt(maxInt);

? ? if (i >= minInt) {

? ? ? sb.append(i - minInt);

? ? }

? ? return sb.toString();

? }


? public static void main(String [] args) throws IOException {

? ? UserIdGenerator userIdGenerator = new UserIdGenerator(

? ? ? ? Paths.get("28K adjectives.txt"),?

? ? ? ? Paths.get("91K nouns.txt"),?

? ? ? ? 20, 120);

? ? for (int i = 0; i < 100; ++i) {

? ? ? System.out.println(userIdGenerator.generate());

? ? }

? }

}

有點(diǎn)樂趣:


AncipitalBoxfuls67

PlanePerfectionists0

TrochaicSerins

UnroundedLightening29

ExpectingRemittors37

UnscorchedCrackbrains75

Conscience-strickenStiles0

MuddleheadedBaptistries7

GauntLoan11

IncompatibleImbalances33

StipitateGabbards62

AppreciatedAntihistamines41

PipyAquanauts83

BiosystematicMan-hours92

NursedCornhusker15

FlocculentCaskets

UnshoedZestfulness70

SulfuricVoyageur90

ParticipialCulpableness27

SunrayVidette43

UllagedKidney

KhedivalSuperaltars74

ArrayedConsorter77

MagnetizedWhooper86

TrimorphousDiscographers59

HolsteredBola89

AnagogicalLinacs19

UnhumbledFlush99

IrritableSuccourer

MultispiralMetallurgy2

SlitheringBelize8

BarkierStimy45

Bull-nosedGlossa45

UnbiasedProscriptions44

BilgierBlackburn7

ScarabaeoidIrreality98

SolidaryMeningiomas1

UnciformSwell5

WhateverTe-hees14

ConsummatedYou'll

BabblingVintners

ControlledTergiversations4

Rock-bottomConstructers77

UltraistLummoxes

ExpectableMicrohenry65

DecentralizedThriller51

SaccharicMisanthropes26

AnatropousMoldwarp20

VelvetyLowlander

MelanousHideaway

PromotiveDodecaphonism3

AdriaticRebutters

InboundEscallops7

RelishableSapotas74

UnjaundicedDichromat71

BloodshotAbuser63

VibrativeKeltic86

VeloceBugbear30

UnclassifiedSeine-maritime

MetonymicalVenturousness36

StemmedHurcheon6

RefreshingBaggages

ExpressibleOmens74

KookiestSegments33

AdmonishingNewsdealer

SchoolgirlishKeitloas45

DisgustfulStrangling9

NoduloseGarnishes

SeaworthyMurphy30

ProximoAcromion13

DisciplinalTransposition74

UnveiledDissolutions60

PrivilegedPorphyrin24

PetitCommonage79

UnrepugnantBwana33

StatelierSordidness

IsorhythmicTulipomania97

DeterministicAbstractness85

IntercrossedTestudos

WolfishOhms4

NimbleTelemeter61

PerthiticExpertises31

WorshipfulHumanness15

NiobeanDecumbency57

PtolemaicGodspeed

DiagonalMultistorey

BrawlingEglantines60

SynclasticWalnuts64

FibroticMordant28

FibrilloseGemels66

MitigativeDredger10

ConfigurationalOberland67

PrerogativeDoits96

BoswellianSandman39

CantharidalEpanodos23

GrippingOracle

Soft-coverDeveloping54

AdjuratorySilas31

MesozoicNorthman

WinterTraveling22



查看完整回答
反對(duì) 回復(fù) 2023-07-28
?
四季花海

TA貢獻(xiàn)1811條經(jīng)驗(yàn) 獲得超5個(gè)贊

組合以下解決方案來(lái)生成字母數(shù)字字符串,即使用 Java Faker 庫(kù)生成名稱,生成隨機(jī)整數(shù)(解決方案取決于您使用的 java 版本)并組合字符串來(lái)構(gòu)建字母數(shù)字字符串。

查看完整回答
反對(duì) 回復(fù) 2023-07-28
?
繁花如伊

TA貢獻(xiàn)2012條經(jīng)驗(yàn) 獲得超12個(gè)贊

試試這個(gè)


public class UserNameGenerator {


    public static void main(String[] args) {


        for (int index = 0; index < 10; index++) {

            System.out.println("Generate: "+ getUserText(null));

        }

    }


    /**

    * this generates a random username

    * @param somePseudoName it shall be used in username if provided

    * @return

    */

    private static String getUserText(String somePseudoName) {

        String[] nameArray = new String[]{"hello", "world", "someday", "mltr", "coldplay"};

        String userName = "";

        if (somePseudoName != null && somePseudoName.length() > 0) {

            userName = somePseudoName;

        } else {

            userName = nameArray[new Random().nextInt(nameArray.length)];

        }

        return userName + getRandomNumber();

    }


    /**

    * this shall create a random number

    * @return a number text

    */

    private static String getRandomNumber() {

        StringBuilder numberText = new StringBuilder();

        int[] numbersArray = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};


        int totalNumbers = new Random().nextInt(3);


        for (int index = 0; index < totalNumbers; index++) {

            numberText.append(numbersArray[new Random().nextInt(numbersArray.length)]);

        }

        return numberText.toString();

    }

}

輸出


Generate: hello8

Generate: mltr

Generate: someday4

Generate: coldplay22

Generate: world

Generate: world

Generate: coldplay79

Generate: world

Generate: coldplay

Generate: coldplay15


查看完整回答
反對(duì) 回復(fù) 2023-07-28
  • 4 回答
  • 0 關(guān)注
  • 302 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)