D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
opt
/
alt
/
ruby34
/
share
/
ri
/
system
/
Array
/
Filename :
sample-i.ri
back
Copy
U:RDoc::AnyMethod[iI"sample:ETI"Array#sample;TF:publico:RDoc::Markup::Document:@parts[o:RDoc::Markup::Paragraph; [I"*Returns random elements from +self+, ;TI"Fas selected by the object given by the keyword argument +random+.;To:RDoc::Markup::BlankLine o; ; [I"LWith no argument +count+ given, returns one random element from +self+:;T@o:RDoc::Markup::Verbatim; [I"(a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] ;TI"a.sample # => 3 ;TI"a.sample # => 8 ;T:@format0o; ; [I"&Returns +nil+ if +self+ is empty:;T@o;; [I"[].sample # => nil ;T; 0o; ; [I"9With a non-negative numeric argument +count+ given, ;TI"Hreturns a new array containing +count+ random elements from +self+:;T@o;; [I" a.sample(3) # => [8, 9, 2] ;TI")a.sample(6) # => [9, 6, 0, 3, 1, 4] ;T; 0o; ; [I"GThe order of the result array is unrelated to the order of +self+.;T@o; ; [I"4Returns a new empty +Array+ if +self+ is empty:;T@o;; [I"[].sample(4) # => [] ;T; 0o; ; [I"%May return duplicates in +self+:;T@o;; [I"a = [1, 1, 1, 2, 2, 3] ;TI".a.sample(a.size) # => [1, 1, 3, 2, 1, 2] ;T; 0o; ; [I"3Returns no more than <tt>a.size</tt> elements ;TI"0(because no new duplicates are introduced):;T@o;; [I"6a.sample(50) # => [6, 4, 1, 8, 5, 9, 0, 2, 3, 7] ;T; 0o; ; [I"`The object given with the keyword argument +random+ is used as the random number generator:;T@o;; [I")a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] ;TI"0a.sample(random: Random.new(1)) # => 6 ;TI"<a.sample(4, random: Random.new(1)) # => [6, 10, 9, 2] ;T; 0o; ; [I"NRelated: see {Methods for Fetching}[rdoc-ref:Array@Methods+for+Fetching].;T: @fileI" array.rb;T:0@omit_headings_from_table_of_contents_below0I"Osample(random: Random) -> object sample(count, random: Random) -> new_ary ;T0[ I"((n = (ary = false), random: Random);T@HFI" Array;TcRDoc::NormalClass00