-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change generated project name to become /^(random_word)-[0-9a-z]{6}$/ #4649
Change generated project name to become /^(random_word)-[0-9a-z]{6}$/ #4649
Conversation
a937313
to
5018f95
Compare
5018f95
to
1acee9b
Compare
portal/src/util/projectname.ts
Outdated
} | ||
return result; | ||
} | ||
|
||
export function deterministicProjectName(num: number): string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is deterministic. You now make it indeterministic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
10, 11, 11 = 32bit
11, 21 = 32bit
first 11 bit => BIP39 word
last 31 bit => base36(26 lower+ 10digit) encode 31 bits => log36(2 ^ 31) <= 6
toString(36) with left-padded zeros
11 => BIP39 word
21 => base36 (26 lower + 10 digit) encode 21 bits => log36(2^21) <= 5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per offline discussion, we can the algorithm to take 42 random bits
first 11 bits => BIP39 word
remaining 31 bits => base36 encode the 31 bits to form a alphanumeric string of length 6. Zero-pad it to make it always of length 6.
portal/src/util/projectname.ts
Outdated
@@ -15,15 +17,25 @@ export function maskNumber(num: number, startAt: number, bits: number): number { | |||
return (num >> startAt) & ((1 << bits) - 1); | |||
} | |||
|
|||
export function getRandomAlphaNumericString(len: number): string { | |||
let result = ""; | |||
const chars = "abcdefghijklmnopqrstuvwxyz0123456789"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
0123456789abc....
6fb1d51
to
844ae7a
Compare
844ae7a
to
e591b8c
Compare
Updated, thanks! |
portal/src/util/projectname.test.ts
Outdated
import { | ||
deterministicProjectName, | ||
extractBits, | ||
maskNumber, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Delete maskNumber and its test. It is no longer used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add
export function projectNameOfCompanyName(companyName: string): string {
const bytes = random();
const [_unused, toBeUsed] = extractBits(bytes);
return `${companyName}-${}`;
}
portal/src/util/projectname.test.ts
Outdated
import { | ||
deterministicProjectName, | ||
extractBits, | ||
maskNumber, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add
export function projectNameOfCompanyName(companyName: string): string {
const bytes = random();
const [_unused, toBeUsed] = extractBits(bytes);
return `${companyName}-${}`;
}
Updated, thanks! |
ref DEV-1612
Uncertainty
whether we want uppercase or not
EDIT: resolved, lower case only
Preview
Screen.Recording.2024-08-23.at.4.43.08.PM.mp4