Register
It is currently Thu Dec 18, 2014 7:46 pm

shuffling a files line with a specific random seed.


All times are UTC - 6 hours


Post new topic Reply to topic  [ 5 posts ] 
Author Message
 PostPosted: Fri May 06, 2011 11:18 am   

Joined: Wed Nov 26, 2008 7:43 pm
Posts: 50
Location: Texas
Hi everyone,

I want to shuffle a file with a specific seed, but I don't know
how to do this with /dev/random or /dev/urandom.

So far I have tried:

/sw/lib/coreutils/bin/sort -R --random-source=/dev/urandom file.txt

but this gives a different random order every time. Anyone know of a
way to shuffle a files lines in a specific seeded random order without having
to build a program for it?


Top
 Profile  
 PostPosted: Mon May 09, 2011 2:34 am   
User avatar

Joined: Tue Apr 27, 2010 2:28 pm
Posts: 172
Location: Czech Republic
What do you mean by "program"? B-)


Top
 Profile  
 PostPosted: Fri Nov 11, 2011 6:50 am   

Joined: Thu Nov 10, 2011 7:31 pm
Posts: 21
he wants to produce the standard sort command
Code:
ls -l | sort -nr
-rwxr-xr-x 1 denton denton  125 2011-11-11 06:47 random
-rwxrwxr-x 1 denton denton 3202 2011-11-10 19:46 colors
-rwxrwxrwx 1 denton denton  175 2011-11-10 18:29 updatesysinfo
-rwx------ 1 denton denton   85 2011-11-09 19:27 sutest
-rwx------ 1 denton denton  826 2011-11-10 17:32 mkhtml
-rwx------ 1 denton denton   58 2011-11-09 19:18 annoying
-rwx------ 1 denton denton   48 2011-11-09 18:50 hello
-rwx------ 1 denton denton  419 2011-11-10 18:35 menutest
-rwx------ 1 denton denton  155 2011-11-10 19:50 nscript
-rwx------ 1 denton denton 1098 2011-11-10 19:08 printfile

and make it display all that in a random order that is the same every time


Top
 Profile  
 PostPosted: Fri Nov 11, 2011 9:12 am   
User avatar

Joined: Tue Apr 27, 2010 2:28 pm
Posts: 172
Location: Czech Republic
Just use a file that does not change instead of /dev/urandom.


Top
 Profile  
 PostPosted: Fri Nov 11, 2011 1:07 pm   
User avatar

Joined: Wed Jun 08, 2011 8:27 am
Posts: 189
Location: outer Shpongolia
afflictedd2 wrote:
but this gives a different random order every time.


It's perfectly normal since you're using /dev/urandom,
which provides random bytes at each run of sort(1).

If you want to shuffle lines the same way every time, then you have to get
the random bytes from /dev/zero, which always provides
the same bytes, i.e. NUL characters.

Code:
sort -R --random-source /dev/zero file.txt


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP