Skip to main content
Commonmark migration
Source Link

#AWK

AWK

BEGIN { srand(n=split("John Jeff Emma Steve Julie.",A)) print A[int(rand()*n+1)] } 

Sorry, Steve!!! :-P

Feeding srand() with a constant shall reproduce the same sequence of rand() values over and over again. On my system gawk and mawk selected Steve but this may not be globally immutable...

But now for something completely different with really seeding srand():

BEGIN { srand() split("John Jeff Emma Steve Julie.",A) print A[int(rand()+1)] } 

Sorry, John!

srand() really seeds the rand() as expected and rand()+1 looks like correctly taking care of the names are stored in A[1] and following indices but because rand() always is smaller than 1, int(rand()+1) always will be 1.

#AWK

BEGIN { srand(n=split("John Jeff Emma Steve Julie.",A)) print A[int(rand()*n+1)] } 

Sorry, Steve!!! :-P

Feeding srand() with a constant shall reproduce the same sequence of rand() values over and over again. On my system gawk and mawk selected Steve but this may not be globally immutable...

But now for something completely different with really seeding srand():

BEGIN { srand() split("John Jeff Emma Steve Julie.",A) print A[int(rand()+1)] } 

Sorry, John!

srand() really seeds the rand() as expected and rand()+1 looks like correctly taking care of the names are stored in A[1] and following indices but because rand() always is smaller than 1, int(rand()+1) always will be 1.

AWK

BEGIN { srand(n=split("John Jeff Emma Steve Julie.",A)) print A[int(rand()*n+1)] } 

Sorry, Steve!!! :-P

Feeding srand() with a constant shall reproduce the same sequence of rand() values over and over again. On my system gawk and mawk selected Steve but this may not be globally immutable...

But now for something completely different with really seeding srand():

BEGIN { srand() split("John Jeff Emma Steve Julie.",A) print A[int(rand()+1)] } 

Sorry, John!

srand() really seeds the rand() as expected and rand()+1 looks like correctly taking care of the names are stored in A[1] and following indices but because rand() always is smaller than 1, int(rand()+1) always will be 1.

deleted 2 characters in body
Source Link
user19214
user19214

#AWK

BEGIN { srand(n=split("John Jeff Emma Steve Julie.",A)) print A[int(rand()*n+1)] } 

Sorry, Steve!!! :-P

Feeding srand() with a constant shall reproduce the same sequence of rand() values over and over again. On my system gawk and mawk selected Steve but this may not be globally immutable...

But now for something completely different with really seeding srand():

BEGIN { srand() split("John Jeff Emma Steve Julie.",A) print A[int(rand()+1)] } 

Sorry, John!

srand() really seeds the rand() as expected and rand()+1 looks like correctly taking care of the names are stored in A[1] and following indices but because rand() always is smaller than 1, int(rand()+1) always will be 1.

#AWK

BEGIN { srand(n=split("John Jeff Emma Steve Julie.",A)) print A[int(rand()*n+1)] } 

Sorry, Steve!!! :-P

Feeding srand() with a constant shall reproduce the same sequence of rand() values over and over again. On my system gawk and mawk selected Steve but this may not be globally immutable...

#AWK

BEGIN { srand(n=split("John Jeff Emma Steve Julie.",A)) print A[int(rand()*n+1)] } 

Sorry, Steve!!! :-P

Feeding srand() with a constant shall reproduce the same sequence of rand() values over and over again. On my system gawk and mawk selected Steve but this may not be globally immutable...

But now for something completely different with really seeding srand():

BEGIN { srand() split("John Jeff Emma Steve Julie.",A) print A[int(rand()+1)] } 

Sorry, John!

srand() really seeds the rand() as expected and rand()+1 looks like correctly taking care of the names are stored in A[1] and following indices but because rand() always is smaller than 1, int(rand()+1) always will be 1.

deleted 2 characters in body
Source Link
user19214
user19214

#AWK

BEGIN { srand(n=split("John Jeff Emma Steve Julie.",A)) print A[int(rand()*n+1)],n } 

Sorry, Steve!!! :-P

Feeding srand() with a constant shall reproduce the same sequence of rand() values over and over again. On my system gawk and mawk selected Steve but this may not be globally immutable...

#AWK

BEGIN { srand(n=split("John Jeff Emma Steve Julie.",A)) print A[int(rand()*n+1)],n } 

Sorry, Steve!!! :-P

Feeding srand() with a constant shall reproduce the same sequence of rand() values over and over again. On my system gawk and mawk selected Steve but this may not be globally immutable...

#AWK

BEGIN { srand(n=split("John Jeff Emma Steve Julie.",A)) print A[int(rand()*n+1)] } 

Sorry, Steve!!! :-P

Feeding srand() with a constant shall reproduce the same sequence of rand() values over and over again. On my system gawk and mawk selected Steve but this may not be globally immutable...

deleted 5 characters in body
Source Link
user19214
user19214
Loading
added 198 characters in body
Source Link
user19214
user19214
Loading
Source Link
user19214
user19214
Loading