Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6973261
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:05:08+00:00 2026-05-27T17:05:08+00:00

The documentation for Array#sample says it can take an rng : If rng is

  • 0

The documentation for Array#sample says it can take an rng:

If rng is given, it will be used as the random number generator.

How can a range function as a random number generator, or why is such thing useful?

Also the hash form suggests there are other options, but I can’t find anything about them. Trying out [1,2,3,4,5].sample(3) behaves just like [1,2,3,4,5].sample(3, random: 1..2).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T17:05:09+00:00Added an answer on May 27, 2026 at 5:05 pm

    The argument should be a random number generator (RNG).

    If one is not provided, it defaults to the “stock” Ruby implementation.

    It can be replaced with an arbitrary RNG, like one that isn’t at all random:

    class NotAtAllRandom
      def self.rand(x=0)
        0
      end  
    end  
    
    > (1..10000).sample(3, random: NotAtAllRandom)
    => [1, 2, 3]
    > (1..10000).sample(3, random: NotAtAllRandom)
    => [1, 2, 3]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Documentation for data.xml/parse says The data is returned as defrecords and can be manipulated
Am I missing something in the Array documentation? I have an array which contains
Documentation says: The Grails team discourages the embedding of core application logic inside controllers,
Documentation says Dictionary keys order is unspecified. I guess it means the first added
Documentation states: Files are included based on the file path given or, if none
In the university we were given the following code sample and we were being
From the OpenAL documentation it looks like if an Sample is one single floating
In Silverlight, the VideoSink.OnSample method is used to get raw webcam data. The function
I can't find any good documentation on the linkable behaviour for cakephp. I'm trying
I'm using Firefox 3.5.7 and within Firebug I'm trying to test the array.reduceRight function,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.