last day (20 days later) » 

7:06 PM
@wayne Hi
 
7:18 PM
a = (1..12).to_a
a.sample(rand(10)) # => [10, 11, 9, 12, 6, 2, 1]
a.sample(2, rand(10)) # =>
# ~> -:3:in `sample': wrong number of arguments (2 for 1) (ArgumentError)
# ~> 	from -:3:in `<main>'
Can you tell me why sample method not taking 2 arguments..
 
7:36 PM
What happened with the older chat room ? :)
I worked it out -
a.sample(2, random: (1..4)) # => [3, 5]
 
Yes, named arguments.
 
But not getting, the point of use of the second argument
 
I asked a moderator to delete the old chat room -- I had accidentally pasted some confidential information into it.
 
Ohkay...
 
If you don't pass in a random number generator, Ruby uses the default, global one; otherwise, it uses the one you pass in.
 
7:50 PM
No.. I am still in confusion..
In the below code :
a.sample(7, random: (1..4)) # => [2, 3, 5, 1, 4, 6, 7]
7 is not in the range...
how is then working.. may be my questions are stupid..
But really not understanding
 
8:03 PM
Check out the source for Array#random in Ruby 2.1. I don't see any evidence that argument random is ever used. It appears that you can pass anything at all as random.
 
tells about the syntax, not the actual usecase
 
It appears that if you pass in something that does not respond to #rand, it is ignored.
 
whatever, but when should I use it ? Actual usecase not clear to me.. The doc didn't mention a single letter on it... strange :(
 
It's very clear in the documentation. You use it when you don't want to use the global PSRNG.
 
Did you read source code ?
I also didn't find Array#random
 
8:15 PM
` keyword_ids[0] = id_random;`. Elsewhere in that file, you will find that id_random is set to the symbol for "random".
 
8:30 PM
Oh, I see. You were looking for a #random method on class Array. No, there isn't one.
 

  last day (20 days later) »