question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

cls.random_sample

See original GitHub issue

I wanted to add a method to BaseProvider that allows for sampling n unique elements. There are situations in which I want to grab several random things, but I want those results to be unique. I just forked and added this to my own fork, but I wanted to run it by you before making a pull request.

    # in faker/provides/__init__.py BaseProvider
    @classmethod
    def random_sample(cls, array=('a','b','c'), number=2):
        """ Returns $number unique elements from $array"""
        return random.sample(array, number)

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:7

github_iconTop GitHub Comments

2reactions
fcurellacommented, Jun 3, 2016

Closed via #358

2reactions
prokaktuscommented, Jun 3, 2016

@fcurella looks nice for me too 👍 But what about unique texts? I can implement it with generating lot of samples and remove duplicates, but it would be nice to have some kind of generator, which always return unique text (address, name, etc.). What do you think about such feature?

I want to use it in my factory for models, which have unique constraints.

I can try to implement this myself in PR, if you think it can be useful.

Read more comments on GitHub >

github_iconTop Results From Across the Web

CLs method (particle physics) - Wikipedia
In particle physics, CLs represents a statistical method for setting upper limits (also called exclusion limits) on model parameters, a particular form of ......
Read more >
Sampling Distributions II - StudyLib
An Example of Sampling Distributions: A Comparison of Simple Random Sampling ... Systematic Sampling, and Cluster Sampling (SRS, STS, SYS, and CLS) Consider ......
Read more >
Why does random.sample used with multiprocessing.Pool ...
This is an open bug in Python 3.8. It is not related to random , the reason is the cleanup of worker processes...
Read more >
sklearn.ensemble.RandomForestClassifier
A random forest is a meta estimator that fits a number of decision tree classifiers on various sub-samples of the dataset and uses...
Read more >
Untitled - Math BLog​Dr. Natalie Hise
CLASINOON. Hybart | 2. Page 2. Choose which sampling technique is used. (R) Random (STR) Stratified (CLS) Cluster (CON) Convenience (SYS) Systematic. STR....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found