11-14-2002
assuming a file size of 5 lines execute both these loops on your machine... you need to type CTRL+C to break the loops when you want...
Quote:
while [ 1 -gt 0 ]; do
expr $RANDOM % 5 + 1
done > newfile
Quote:
while [ 1 -gt 0 ]; do
expr \( 1 + $RANDOM \) \* 5 / 32768
done > newfile2
you will notice that newfile2 for most of the time won't contain 5... so the second way won't lead to a uniform distribution between 1 and $nlines... in fact most of the time it won't generate $nline at least for small $nline values...
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
My problem is as follow and i hope you can help:
I currently have this function:
stored_word()
{
number=$RANDOM
let "number %= 21"
case $number in
0 ) echo "energy" ;; 1 ) echo "touch" ;;
2 ) echo "climbing" ;; 3 ) echo "declare" ;;
4 ) echo "marry" ;; 5 ) echo "relax" ... (8 Replies)
Discussion started by: keyvan
8 Replies
2. Shell Programming and Scripting
I need to use the $RANDOM command to get a line from a list of lines in a file randomly.
file is
help
go
three
house
film
how do i randomly get one word without looking into the file? (6 Replies)
Discussion started by: relle
6 Replies
3. Shell Programming and Scripting
I have a text file with hundreds of lines, i wish to run a script and reads a random line to pass it to another command line such as:
for line in `cat file |grep random line`; do echo $line |mail my@example.com ; done
thank you (6 Replies)
Discussion started by: Bashar
6 Replies
4. Ubuntu
Hi
I am new to expect. Please if any one can help on my issue its really appreciable. here is my issue:
I want expect script for random passwords and random commands generation.
please can anyone help me?
Many Thanks in advance (0 Replies)
Discussion started by: vanid
0 Replies
5. Shell Programming and Scripting
Hi experts,
My csv file looks like this
U;cake;michael;temp;;;;
U;bread;john;temp;;;;
U;cocktails;sarah;temp;;;;
I'd like to change the value fo 2nd column to cf+random number , which will look maybe something like this
U;cf20187;michael;temp;;;;
U;cf8926;john;temp;;;;... (7 Replies)
Discussion started by: tententen
7 Replies
6. Shell Programming and Scripting
I have a file that needs to be parsed into multiple files every time there line contains a number 1. the problem i face is the lines are random and the file size is random. an example is that on line 4, 65, 187, 202 & 209 are number 1's so there has to be file breaks between all those to create 4... (6 Replies)
Discussion started by: darbs121
6 Replies
7. Shell Programming and Scripting
Need to use dd to generate a large file from a sample file of random data. This is because I don't have /dev/urandom.
I create a named pipe then:
dd if=mynamed.fifo do=myfile.fifo bs=1024 count=1024
but when I cat a file to the fifo that's 1024 random bytes:
cat randomfile.txt >... (7 Replies)
Discussion started by: Devyn
7 Replies
8. UNIX for Dummies Questions & Answers
Hello
I created 3 files by:
dd if=/dev/urandom bs=1024 count=1000000 of=./testfile1
dd if=/dev/urandom bs=1024 count=5000000 of=./testfile2
dd if=/dev/urandom bs=1024 count=10000000 of=./testfile3
Now I want to know how to make a change in a specific byte and/or line of theses files? (2 Replies)
Discussion started by: frhling
2 Replies
9. Shell Programming and Scripting
I have a file contains thousands of lines. I want to insert n random numbers into each line at
specific position. Like this:
0 22……
1 33……
……
……
I want to insert 3 random numbers from position 2 to 4 into each line.
0 325 22……
1 685 33……
……
……
Please use CODE tags when... (8 Replies)
Discussion started by: hhdzhu
8 Replies
10. UNIX for Beginners Questions & Answers
Input file:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 (6 Replies)
Discussion started by: Sagar Singh
6 Replies
LEARN ABOUT DEBIAN
crypt::openssl::random
Random(3pm) User Contributed Perl Documentation Random(3pm)
NAME
Crypt::OpenSSL::RSA - RSA encoding and decoding, using the openSSL libraries
Crypt::OpenSSL::Random - Routines for accessing the OpenSSL pseudo-random number generator
SYNOPSIS
use Crypt::OpenSSL::Random;
Crypt::OpenSSL::Random::random_seed($good_random_data);
Crypt::OpenSSL::Random::random_egd("/tmp/entropy");
Crypt::OpenSSL::Random::random_status() or
die "Unable to sufficiently seed the random number generator".
my $ten_good_random_bytes = Crypt::OpenSSL::Random::random_bytes(10);
my $ten_ok_random_bytes = Crypt::OpenSSL::Random::random_pseudo_bytes(10);
DESCRIPTION
Crypt::OpenSSL::Random provides the ability to seed and query the OpenSSL library's pseudo-random number generator
EXPORT
None by default.
Static Methods
random_bytes
This function, returns a specified number of cryptographically strong pseudo-random bytes from the PRNG. If the PRNG has not been
seeded with enough randomness to ensure an unpredictable byte sequence, then a false value is returned.
random_pseudo_bytes
This function, is similar to c<random_bytes>, but the resulting sequence of bytes are not necessarily unpredictable. They can be used
for non-cryptographic purposes and for certain purposes in cryptographic protocols, but usually not for key generation etc.
random_seed
This function seeds the PRNG with a supplied string of bytes. It returns true if the PRNG has sufficient seeding. Note: calling this
function with non-random bytes is of limited value at best!
random_egd
This function seeds the PRNG with data from the specified entropy gathering daemon. Returns the number of bytes read from the daemon
on succes, or -1 if not enough bytes were read, or if the connection to the daemon failed.
random_status
This function returns true if the PRNG has sufficient seeding.
BUGS
Because of the internal workings of OpenSSL's random library, the pseudo-random number generator (PRNG) accessed by Crypt::OpenSSL::Random
will be different than the one accessed by any other perl module. Hence, to use a module such as Crypt::OpenSSL::Random, you will need to
seed the PRNG used there from one used here. This class is still advantageous, however, as it centralizes other methods, such as
random_egd, in one place.
AUTHOR
Ian Robertson, iroberts@cpan.com
SEE ALSO
perl(1), rand(3), RAND_add(3), RAND_egd(3), RAND_bytes(3).
POD ERRORS
Hey! The above document had some coding errors, which are explained below:
Around line 62:
'=item' outside of any '=over'
Around line 93:
You forgot a '=back' before '=head1'
perl v5.14.2 2007-05-20 Random(3pm)