Question on Ramdom Number


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Question on Ramdom Number
# 8  
Old 05-19-2005
Thanks everyone.
# 9  
Old 05-19-2005
Quote:
Originally Posted by jim mcnamara
vgersh99 -

put your code inside a tight loop, echo $rnd and you'll see the problem with it.
true - it's NOT a true random number generator - understood.
was it solaris 10 providing /dev/random - don't quite remember.

Quote:
Originally Posted by jim mcnamara
Plus, not everyone has nawk... Smilie Me, for example.
....how 'bout gawk? Smilie

I agree - it's not a generic solution
[bow in shame...]
# 10  
Old 05-19-2005
When I was writing my password generator I discovered that the ksh internal random number generator was not very good. I wound up writing my own, which turned out to be very hard. It's called "tigershark" and it is in my password generator called "swordfish". It's fast and portable. It has moderately long period, 9194221792649674751. And it passes the diehard test suite.

swordfish --- a password generator
# 11  
Old 05-19-2005
well how about this?

rnd=$(perl -e 'printf int(rand(0,36)+0.5)')
# 12  
Old 05-19-2005
Quote:
Originally Posted by reborg
well how about this?

rnd=$(perl -e 'printf int(rand(0,36)+0.5)')
it's a bit better then nawk, but still I'm still seeing repetitive values when put under the 'tight loop'.

don't really know if it's because the generator is better OR takes longer to load 'perl' [vs. loading nawk] and therefore the time-based [???] generation is a bit skewed [and better].
# 13  
Old 05-19-2005
Quote:
Originally Posted by Perderabo
When I was writing my password generator I discovered that the ksh internal random number generator was not very good. I wound up writing my own, which turned out to be very hard. It's called "tigershark" and it is in my password generator called "swordfish". It's fast and portable. It has moderately long period, 9194221792649674751. And it passes the diehard test suite.

swordfish --- a password generator
that's great - thanks for sharing!
# 14  
Old 05-19-2005
Quote:
Originally Posted by vgersh99
it's a bit better then nawk, but still I'm still seeing repetitive values when put under the 'tight loop'.

don't really know if it's because the generator is better OR takes longer to load 'perl' [vs. loading nawk] and therefore the time-based [???] generation is a bit skewed [and better].
No, it is just better, because the time used to seed it has finer granularity, you would get results similar to awk if you used:

perl -e 'srand(time()); printf int(rand(0,36)+0.5)'
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Noob question: How to check the total number of inputs entered by user?

Say I have this line: read -p "Enter 3 numbers: " num1 num2 num3; I want to write a while loop that repeatedly asks for input if the number of inputs entered is not equal to 3. I don't know the correct command to find the number of inputs entered. Help, please? (4 Replies)
Discussion started by: jejemonx
4 Replies

2. Shell Programming and Scripting

awk to find number in a field then print the line and the number

Hi I want to use awk to match where field 3 contains a number within string - then print the line and just the number as a new field. The source file is pipe delimited and looks something like 1|net|ABC Letr1|1530||| 1|net|EXP_1040 ABC|1121||| 1|net|EXP_TG1224|1122||| 1|net|R_North|1123|||... (5 Replies)
Discussion started by: Mudshark
5 Replies

3. Shell Programming and Scripting

Help with sort word followed by exponential number and numeric number at the same time

Input file: ID_34 2E-69 2324 ID_1 0E0 3254 ID_1 0E0 5434 ID_5 0E0 436 ID_1 1E-14 2524 ID_1 5E-52 46437 ID_3 65E-20 45467 ID_1 0E0 6578 ... Desired output file: ID_1 0E0 6578 ID_1 0E0 5434 ID_1 0E0 3254 ID_1 5E-52 46437 ID_1 1E-14 2524 ID_3 65E-20 45467 (5 Replies)
Discussion started by: cpp_beginner
5 Replies

4. Shell Programming and Scripting

The difference between end number in the early row and the start number in the next

Hi Power User, I'm trying to compute this kind of text file format: file1: jakarta 100 150 jakarta 170 210 beijing 220 250 beijing 260 280 beijing 290 320 new_york 330 350 new_york 370 420 tokyo 430 470 tokyo 480 ... (2 Replies)
Discussion started by: anjas
2 Replies

5. Shell Programming and Scripting

AWK print number of records, divide this number

I would like to print the number of records of 2 files, and divide the two numbers awk '{print NR}' file1 > output1 awk '{print NR}' file2 > output2 paste output1 output2 > output awl '{print $1/$2}' output > output_2 is there a faster way? (8 Replies)
Discussion started by: programmerc
8 Replies

6. Shell Programming and Scripting

changing number in bash (number is in form of string)

I have a txt file as database. when i run my program what it does is it ask me for 3 name and stored in the file as name1:name2:name3:1 when u enter 3 name it add those in file as above format and add 1 at the end. I what i want is if i enter same names again it changes that 1 to 2 and so... (3 Replies)
Discussion started by: Learnerabc
3 Replies

7. Shell Programming and Scripting

Question on awk for finding the column number using a match word

Hi Guys, Please help me out in my situation of writing a shell script Exampl:I have a output like asnapply 1 2 3 apply_server=1 apply_schema=ASN asnapply 1 2 3 apply_server=2 apply_schema=ASN Now i need output like asnacmd applysever=1 applyschema=ASN stop asnacmd applysever=2... (16 Replies)
Discussion started by: mallak
16 Replies

8. UNIX for Dummies Questions & Answers

Quick question about set number

In my .exrc file I have line numbers turned on but it adds an indent. I don't like this, is there a way to have the line numbers at the left edge of my terminal instead of indented? Here's my .exrc 1 set ignorecase noslowopen report=0 autoindent showmatch showmode nu 2 set... (4 Replies)
Discussion started by: ebadamageplan
4 Replies

9. UNIX for Dummies Questions & Answers

question about printing number of lines in a file

as the title, I had try use "wc -l test.txt" but it give me "<many spaces> 384 test.txt" but the result I want is just "384" could any person can help me that? Thx:( (5 Replies)
Discussion started by: a8111978
5 Replies
Login or Register to Ask a Question