Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

random number

Status
Not open for further replies.

ovince

Programmer
Feb 27, 2007
55
FR
Hi,

Is it posible to generate (for example 1000) random numbers in a such a way to fill a square in plane in awk?

thanks
oliver




 
In your awk man pages have a look at the rand() function.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hi

Is easy to generate 1000 random numbers...
Code:
awk 'BEGIN{for(i=0;i<1000;i++)print rand()}'
... but I do not understand the "fill a square in plane" part.

Maybe for the plane you want pairs of random numbers, both in a given value interval.

So if you want random point coordiantes inside a square like this :
[tt] |
y|...+-------+
| | |
| | |
| | |
|...+-------+
| : :
--+-------------
0| x<--d-->[/tt]
Code:
awk -vx=[green][i]x[/i][/green] -vy=[green][i]y[/i][/green] -vd=[green][i]d[/i][/green] 'BEGIN{for(i=0;i<1000;i++)print int(rand()*d+x)","int(rand()*d+y)}'
I hope you do not want to rotate that square.

Feherke.
 

:) I will rotate it in gnuplot ... just to generate it first :)

well I would like to have random pairs between

1.07<x<1.19 and 4.66<y<6.14

and I put (no int)

awk -vx=1.07 -vy=6.14 -vd=0.12 'BEGIN{for(i=0;i<10000;i++)print (rand()*d+x),(rand()*d+y)}' > ran.aw

but I do not get the square.








 
ie I have different scales on x and y so the square is not a square
 
and finally I have 100 filled squares that rotate in gnuplot :)


awk '{for(i=0;i<10000;i++)print rand()*$3+$1,rand()*$4+$2}' randIn.dat > ranOut.dat


koszonom Feherke (I hope I do not mistake with Koszonom :))
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top