Path: csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Robert Klemme Newsgroups: comp.lang.java.programmer Subject: Re: Random permutations [was Re: Libraries for sysadmins?] Date: Sat, 5 Mar 2016 12:11:33 +0100 Lines: 18 Message-ID: References: <2cec6af2-9636-4a2a-8849-b01286c0814c@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net cG856TlIysselkM/L30KrwnGJb7oCKUN688kj+8AMqhYXlULM= Cancel-Lock: sha1:bL1QHTPsfT6XnSgj+3AqZsPI7E8= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 In-Reply-To: Xref: csiph.com comp.lang.java.programmer:33930 On 05.03.2016 00:56, Sebastian wrote: > This is good if you need about as many elements in the result as are in > the range. But if the range is large and you need only a few elements, > it may be better to generate numbers (without duplicates), like this: > > new Random().ints(1, 50).distinct().limit(6) Are you sure this has the same probability characteristics as picking six random items from a list of 49? Cheers robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/