Skip to content
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

seed for random generator #29

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions lib/src/faker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import 'conference.dart';
import 'currency.dart';
import 'food.dart';
import 'guid.dart';
import 'image.dart';
import 'internet.dart';
import 'job.dart';
import 'person.dart';
Expand All @@ -23,7 +22,6 @@ class Faker {
final Currency currency;
final Food food;
final Guid guid;
final Image image;
final Internet internet;
final Job job;
final Lorem lorem;
Expand All @@ -39,7 +37,6 @@ class Faker {
currency = const Currency(),
food = const Food(),
guid = const Guid(),
image = const Image(),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove image?

internet = const Internet(),
job = const Job(),
lorem = const Lorem(),
Expand Down
24 changes: 0 additions & 24 deletions lib/src/internet.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import '../faker.dart';
import 'data/person/firstnames.dart';
import 'data/user_agent/user_agent.dart';
import 'data/user_agent/user_agent_data.dart';
import 'data/person/lastnames.dart';
import 'random_generator.dart';

Expand Down Expand Up @@ -152,25 +149,4 @@ class Internet {
/// faker.internet.password();
/// ```
String password({int length = 10}) => random.string(length, min: length);

/// Generates an User Agent from Predefined Dictionary
/// with the given [osName] if provided.
/// if not provided [osName] is an empty String or ['']
///
/// Example:
/// ```dart
/// faker.internet.userAgent();
/// faker.internet.userAgent(osName:'ios');
/// ```
String userAgent({String osName = ''}) => random
.element(UserAgents.fromJson(userAgentDatas)
.userAgents
.map((e) => e)
.where(
(element) =>
element.osName.toLowerCase().contains(osName.toLowerCase()),
)
.toList())
.userAgent
.toString();
Comment on lines -155 to -175
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these being deleted?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep. My bad. It seems that I used and older fork of faker, without the userAgent and image commit. Can you omit those changes, or should I make another pull request? Only added a method in random_generator.dart

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make a new commit that brings those deletions back if possible.

}
11 changes: 11 additions & 0 deletions lib/src/random_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var _rng = Random();

const random = RandomGenerator();


class RandomGenerator {
const RandomGenerator();

Expand Down Expand Up @@ -91,4 +92,14 @@ class RandomGenerator {
String fromPatternToHex(List pattern) => element(pattern).splitMapJoin('#',
onMatch: (_) =>
numbers(16, 1).map((number) => number.toRadixString(16)).join());

/// Sets [ seed ] as the seed of random generator [_rng].
///
/// Example:
/// ```dart
/// faker.RandomGenerator.setSeed(1);
/// ```
void setSeed(int seed){
_rng = Random(seed);
}
}