a few days back I had asked for help creating an [x,y,z] dims piddle
where every element was a random integer between 0 and 255. A couple
of suggestions set me off to learn dummy(), and I also learned the
correct use of random() (thanks, Daniel and Chris). Today, I figured
out a way to make any dimension piddle filled with random integers
between any two integers <max> and <min>.

$a = (( (zeroes( <dim> [, <dim> ..] ))->random * ( <max> - <min> + 1
)) + <min> )->floor

The thing is, the above works whether I use zeroes or ones, which, I
am guessing is because internally PDL::new_from_specification is being
used to create a template for the piddle.

    perldl> $a = (( (zeroes( 5, 5, 3 ))->random * ( 1000 - 500 + 1 ))
+ 500 )->floor
    perldl> p $a
    perldl> p $a
    [
     [
      [ 759  780  741  581  828]
      [1000  521  826  706  904]
      [ 583  972  852  812  987]
      [ 680  545  512  620  716]
      [ 588  737  659  641  919]
     ]
     [
      [664 535 829 972 524]
      [970 728 859 775 849]
      [783 511 909 737 952]
      [746 602 817 625 824]
      [557 702 735 529 934]
     ]
     [
      [839 814 908 984 590]
      [518 761 661 877 523]
      [904 728 810 528 820]
      [530 576 850 639 941]
      [831 874 662 965 601]
     ]
    ]

Not a big thing for you seasoned pros, but very exciting for a
beginner like me. I have added the above to the cookbook at
http://sourceforge.net/apps/mediawiki/pdl/index.php?title=Create_a_piddle_of_any_dimensions_with_every_element_a_random_integer_between_MAX_and_MIN

-- 
Puneet Kishor http://www.punkish.org
Carbon Model http://carbonmodel.org
Charter Member, Open Source Geospatial Foundation http://www.osgeo.org
Science Commons Fellow, http://sciencecommons.org/about/whoweare/kishor
Nelson Institute, UW-Madison http://www.nelson.wisc.edu
-----------------------------------------------------------------------
Assertions are politics; backing up assertions with evidence is science
=======================================================================

_______________________________________________
Perldl mailing list
[email protected]
http://mailman.jach.hawaii.edu/mailman/listinfo/perldl

Reply via email to