[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Enhancement Requests: Add a seed value option to sort and shuf
From: |
Thomas Müller |
Subject: |
Enhancement Requests: Add a seed value option to sort and shuf |
Date: |
Wed, 20 Nov 2013 18:29:52 +0100 |
Hi,
I would appreciate if sort (and shuf) had an option to specify a seed
value that could be set during random sort in order to always get the
same permutation of an input file.
Behavior now:
Two consecutive calls to sort -R give different results:
$ echo 'a b c' | tr ' ' '\n' | sort -R
a
b
c
$ echo 'a b c' | tr ' ' '\n' | sort -R
b
c
a
Wanted behavior:
Given the same seed value two consecutive calls to sort -R generate
the same permutation:
$ echo 'a b c' | tr ' ' '\n' | sort -R --seed-value=42
c
b
a
$ echo 'a b c' | tr ' ' '\n' | sort -R --seed-value=42
c
b
a
I acutally already created a sort version with the described behavior
using a new version of
isaac_seed called isaac_seed_value:
void
isaac_seed_value (struct isaac_state *s, uint32_t seed_value)
{
isaac_seed_start (s);
if (seed_value > 0) {
ISAAC_SEED(s, seed_value);
} else {
{ pid_t t = getpid (); ISAAC_SEED (s, t); }
{ pid_t t = getppid (); ISAAC_SEED (s, t); }
{ uid_t t = getuid (); ISAAC_SEED (s, t); }
{ gid_t t = getgid (); ISAAC_SEED (s, t); }
{
xtime_t t = gethrxtime ();
ISAAC_SEED (s, t);
}
}
isaac_seed_finish (s);
}
This basically uses a deterministic seed value if seed_value is
different from 0 and behaves like isaac_seed if not. Of course some
code in rand-isaac.{c,h}, randread.{c,h} and sort.c had to be changed
as well.
Please tell me if you think that this feature and the implementation
make sense. If so I would glady submit my changes to the git
repository.
Best,
Thomas
- Enhancement Requests: Add a seed value option to sort and shuf,
Thomas Müller <=