유연하고 직관적인 구문을 사용하여 랜덤 문자열을 생성하는 Flutter/Dart 패키지입니다. 길이, 문자 집합, 접두사, 접미사 및 패턴과 같은 다양한 사용자 정의 옵션을 지원합니다. 고유 식별자, 비밀번호, 토큰 또는 테스트 데이터를 생성하는 데 이상적입니다. 가볍고 잘 문서화되어 있으며 Android, iOS, Web, macOS, Windows, Linux 등 모든 주요 플랫폼과 호환됩니다. 개발자가 최소한의 코드로 복잡한 랜덤 문자열 규칙을 정의할 수 있습니다. 동적이고 안전하거나 일관된 랜덤 텍스트 생성이 필요한 애플리케이션에 적합합니다.
사용 사례
보안 비밀번호 생성
고유 ID 또는 토큰 생성
테스트 데이터 생성
랜덤 콘텐츠 생성
문자열 패턴 사용자 정의
주요 기능
사용하기 쉬운 구문
길이 및 패턴 제한을 지원합니다
사전 및 사후 접두사 및 접미사 설정 가능
다중 문자 집합 옵션
크로스 플랫폼 호환성
확장 가능한 구성
적합한 대상
랜덤 문자열이 필요한 앱 개발자
테스트 자동화 엔지니어
보안 중심 애플리케이션
프로토타이핑 도구
데이터 생성 유틸리티
고려 사항
난수성이 보안 요구 사항을 충족하는지 확인하십시오
특정 사용 사례에 대한 생성된 문자열 검증
고주파 생성에서 성능에 유의하세요
원본 README
연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.
Style Random
Random string generator with easy syntax and many complex options. Specify random template by character classes, define
length, order by classes, add conditions like starting with, ending with or duplication.
Features
The random code generator that can be used for many needs is created with a single template. This template is parsed at
the beginning and generates random codes suitable for all conditions.
style_random is basically designed to customize random codes such as data identifier, OTP, 2FA, short
link in the style_dart backend framework.
In addition, when we create the customized protocol in the web socket implementation, an additional small security
measure is aimed by verifying that the random message identifiers created by the client or received from the server are
created with the same secret template.
Getting started
Define Template
voidmain() {
final generator = RandomGenerator("/l(5)A{-}/l(10)[#a]/e(#)/s({AEIOU})");
}
What does it mean?
In order;
5 capital letters.
1 -
10 lowercase letters or numbers. (unordered)
With Conditions;
Must start with a capital vowel
Must end with a number
Generate
voidmain() {
final generator = RandomGenerator("/l(5)A{-}/l(10)[#a]/e(#)/s({AEIOU})");
gen.generateString(); // x6
}
The things that make up a template are expressions and options.
Expressions are character classes, character groups, or static characters. These will be explained
below.
a [A#] {-}
a lowercase letters [A#] uppercase letters or numbers {-} just -
The options at the end of the template affect the entire template. So we can call them global options.
<option><class> this option only effect the class. <class1><class2><option> and this option effect all template.
All options start with /<option-name>.
In addition, options can take parameters such as /<option-name>(<param1>,<param2>).
/l(10) a for example l is the length option and when given to a character class it determines how many instances of that class will be produced. a # /l(15) Similarly, it determines the length of the random value produced when given as a global option.
We can group character classes instead of one character class. The difference between grouping and regular typing is
order. While it is sequential in normal writing, it randomly selects from among the group.
a [A#] {-}
This statement produces a String with a , [A#] and - in order.
But the expression [A#] selects out of order in itself.
In the example below we can see this
voidmain() {
var gen = RandomGenerator("/l(5)a /l(5)[A#] {-}");
print(gen.generateString()); // x6
}
All outs ordered by a(lower letters) -> [A#](group) -> -(static)
But A(capital letters) and #(numbers) are mixed-order within themselves.
s any specific character (ASCII 33-47, 58-64, 91-96, 123-126)
w any specific character exclude url specific characters
Group
[<cl><cl>] character class group. No sorting is done within the group.
[a #] lower case letters or numbers
Static Expression
Static characters are expressed with {}. Static expressions instantiate the contents as they are.
E.g. {-} , {42} , {xyz}
Options
/l() Length
The length option can be added anywhere. It determines the length of that expression when added to an expression, and
the length of the entire expression when added to global options.
The length option can take a fixed number or a range.
Fixed
When a constant number like /l(<n>) is given, exactly n times produced.
Range
The length can be defined within a certain range.
If a range is given as a length, the generator checks the parent-child lengths. If it is impossible, it will throw an
error when RandomGenerator is defined.
This impossibility arises when the maximum value of the child is less than the minimum set by the parent (for
example, global /l()) for that child, etc.
There are 3 ways of range definition:
/l(<min>-<max>) minimum and maximum are defined. /l(-<max>) maximum is defined. If there is no minimum set by parent for this expression, the minimum can be 0. So from
this expression it may not be created at all. /l(<min>-) minimum is defined, maximum is infinity. The length must be restricted by the parent when this expression
is used. Otherwise, it will throw an error with the message "max unbounded".
If the range is used as the length, the generator randomly determines the lengths in these intervals when it is built.
The length of static expressions is always the length of the String inside.
{-} : auto add /l(1)
{mehmet} : auto add /l(6)
The Length option automatically determines the length of expressions without a length specified by looking at the child
parent relationships.
All results in the example below conform to the same template
End options specifies the conditions for the start or end(last index) of expressions.
These end expressions are defined as /option-name(classes or characters).
It can take more than one parameter. Character class names must be direct, and specific characters must inside of {}.
Parameters are separated by commas.
For example:
/s(a,{-},{@5c}) . any character (ASCII 33-126) BUTmust start with;
a lower case letters
OR
{-} the character of -
OR
{@5c} characters of "@" or "5" or "c"
There are 4 types of end options.
/s(<cl>|<char>) Starts with
/e(<cl>|<char>) Ends with
/<(<cl>|<char>) Not start with
/>(<cl>|<char>) Not end with
If you are using it for security purposes (for example, to generate a key), preventing(or to reduce) duplication or templates whose random values are similar to each other will NOT make your key more secure. It makes it more INSECURE.
Impossibility
While the template is being built, it is checked whether this condition is possible in most cases.
E.g. /s(a) # in the expression, generation with the condition is impossible. Because the condition is to create an
instance from class #, starting from class a. But any # does not contain any a.
Many possibilities are reviewed and if there is an impossibility, an error is thrown during the build. Loops are limited
to the square of the length to avoid endless loops due to missed debugging.
An error is thrown when these conditions conflict. If the parent has the same condition, the child is not accepted and
gives an error.
End Options Examples
/s(#)/e(#)./l(20) 20 any character. It must start with a number and end with a number.
/s(#)/>(s)./l(20) 20 any character. It must start with a number and not end with a specific characters.
On Generate Length
If the range is used as the length, the generator randomly determines the lengths in these intervals when it is built.
This means that all results will be of the same length. But if you want the length to be re-selected for each instance (
with some performance degradation), then onGenerateLength: true should be.
voidmain() {
var gen = RandomGenerator(
"/l(1-9)# /l(1-9)a /l(10)",
onGenerateLength: true
);
}
In this example, numbers of length 1-9(random length in this range) and lowercase letters of length 1-9 are produced,
orderly.
If we want these lengths to change with each election, the result may be like this: