[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Generating pseudo-random integers
From: |
Jim Meyering |
Subject: |
Re: Generating pseudo-random integers |
Date: |
Sat, 05 Feb 2011 08:51:14 +0100 |
Melikamp T. Medley wrote:
> Thanks!
>
> I think I want to write a utility that prints pseudo-random
> integers (I have in CL, but I like it fast, so this time in C),
> and link it with coreutils. I looked at Paul Eggert's work,
> and I won't be able to do any better than that if I spend
> years on it :) I want to print uniformly distributed integers
> fast, formatted, in bulk if needed. And I want to call it roll.
> Let me know if you have a word of advice.
>
> On 02/04/2011 11:35 PM, Eric Blake wrote:
>> Using just coreutils, though, I'm afraid your options are slim. You
>> could use 'seq 0 9 | sort -R | head -n1' (or use shuf instead of sort
>> -R) to generate one random number at a time, but that gets expensive.
>> Or, if you don't mind limiting yourself to 62**6 values (instead of the
>> more traditional 2**32), you could do 'mkdir tmp; mktemp -u -p tmp
>> XXXXXX'. But that's the extent of coreutils' randomness exposed to the
>> user.
It's hard to justify writing a new program in C
when you can do the job with a Perl one-liner:
$ perl -le 'foreach (1..20) { print int rand 1000 }'
423
619
917
396
957
345
892
13
424
519
898
689
208
383
605
196
384
893
618
344
However, adding an *option* to shuf might make sense,
since you can already give shuf both a range and a count
of how many numbers to print.
- Generating pseudo-random integers, Melikamp T. Medley, 2011/02/04
- Re: Generating pseudo-random integers, Eric Blake, 2011/02/04
- Re: Generating pseudo-random integers, Melikamp T. Medley, 2011/02/05
- Re: Generating pseudo-random integers, Bob Proulx, 2011/02/05
- Re: Generating pseudo-random integers, Melikamp The Medley, 2011/02/05
- Re: Generating pseudo-random integers, Bob Proulx, 2011/02/05
- Message not available
- Message not available
- Re: Generating pseudo-random integers, Melikamp The Medley, 2011/02/05
- Re: Generating pseudo-random integers, Bob Proulx, 2011/02/05
- Re: Generating pseudo-random integers, Melikamp T. Medley, 2011/02/07
- Re: Generating pseudo-random integers,
Jim Meyering <=
- Re: Generating pseudo-random integers, PĂˇdraig Brady, 2011/02/05
- Re: Generating pseudo-random integers, Jim Meyering, 2011/02/05