Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^2: inclusive rand

by Lotus1 (Vicar)
on Mar 13, 2017 at 18:34 UTC ( [id://1184463]=note: print w/replies, xml ) Need Help??


in reply to Re: inclusive rand
in thread inclusive rand

This finds the smallest difference between any two random values.

use strict; use warnings; use List::MoreUtils qw(uniq); use List::Util qw(min); my @samples = sort { $a <=> $b } uniq map {rand} 1..3000; print scalar @samples, " unique samples.\n"; print "The minimum difference is ", min map { $samples[$_] - $samples[ +$_-1] } 1..$#samples; __END__ 2861 unique samples. The minimum difference is 3.0517578125e-005

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1184463]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (2)
As of 2024-04-25 22:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found