Jump to content

Pseudorandom number generator image: Difference between revisions

added Raku programming solution
mNo edit summary
(added Raku programming solution)
Line 168:
save("randombw.png", rand(Float16, 1000, 1000))
</lang>
 
=={{header|Raku}}==
MoarVM [https://github.com/MoarVM/MoarVM/blob/master/3rdparty/tinymt/tinymt64.c uses Mersenne Twister] as its PRNG but a prime seeder is not mandatory.
<lang perl6># 20200818 Raku programming solution
 
use Image::PNG::Portable;
 
srand 2⁶³ - 25; # greatest prime smaller than 2⁶³ and the max my system can take
 
my @data = < 250 500 1000 1500 >;
 
@data.map: {
my $o = Image::PNG::Portable.new: :width($_), :height($_);
for ^$_ X ^$_ -> @pixel { # about 40% slower if split to ($x,$y) or (\x,\y)
$o.set: @pixel[0], @pixel[1], 255.rand.Int, 255.rand.Int, 255.rand.Int
}
$o.write: "image$_.png" or die;
}</lang>
{{out}}
<pre>file image*.png
image1000.png: PNG image data, 1000 x 1000, 8-bit/color RGBA, non-interlaced
image1500.png: PNG image data, 1500 x 1500, 8-bit/color RGBA, non-interlaced
image250.png: PNG image data, 250 x 250, 8-bit/color RGBA, non-interlaced
image500.png: PNG image data, 500 x 500, 8-bit/color RGBA, non-interlaced
</pre>
351

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.