Not to quibble... but
f2 =: 3 : 'y * ?(#y)#0'
has a related trouble to the original post with
argument rank > 1 ... f1 is actually better in
extending "to work with arrays of any shape". To
try to gain some speed, perhaps you really meant
to say:
f2 =: 3 : 'y * ?($y)$0'
- joey
At 10:59 -0400 2008/06/30, Henry Rich wrote:
What you executed was:
3 3 * ?0
which is
3 3 * (?0)
in other words, you asked for one number, then multiplied it by 3 twice.
You could have your verb apply to atoms by giving it a rank of 0:
f1 =: 3 : 'y * ?0'"0
Or, you could design it to work with arrays of any shape:
f2 =: 3 : 'y * ?(#y)#0'
Working with bigger arrays is faster, but perhaps not by enough
to be worth the trouble. Depends on your application.
Henry Rich
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
Benoît Roesslinger
Sent: Monday, June 30, 2008 10:46 AM
To: [email protected]
Subject: [Jprogramming] Random number generation
Hi,
I am new to J and when doing some experiments with random
number generation
I stumbled across the following behavior, which wasn't what
I'd expect :
f=: 3 : 'y * ?0'
f 3
2.91414
f 3
0.139888
f 3
0.990328
OK so far, but when I tried:
f 3 3
it gives me :
0.0403801 0.0403801 (same values!)
whereas I'd expect a behavior much like the one of '?'...
Is this behavior normal ?
Suppose I want to create a function to generate a random
deviate from a
distribution (normal for instance) with some parameters (mean
and sd for
instance) that will work in the same fashion as '?', ie it is
possible to
generate lots of random deviates at once using code such as :
distri 100 $
x, where x would represent parameters, what is the best way to go ?
Many thanks in advance!
Benoît.
----------------------------------------------------------------------
For information about J forums see
http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm