POV-Ray : Newsgroups : povray.pov4.discussion.general : Improve Random number generation in future versions of POVRay : Improve Random number generation in future versions of POVRay Server Time
24 Sep 2021 14:06:28 EDT (-0400)
  Improve Random number generation in future versions of POVRay  
From: Warren
Date: 15 Jun 2021 13:20:00
Message: <web.60c8e02f5823372c1d602a3e756b296@news.povray.org>
Some years ago, I read documentation about Random number generation in the C++
Language, in particular the new C++11 (the 2011 revision of C++ for those not
familiar with this language) language revision with, new types that allow a more
convenient random number generation. A example sometimes being more meaningful,
consider this code excerpt written in C++:

----
constexpr long unsigned SEED = 1234;

std::mt19937 mersenne{ SEED };
std::uniform_int_distribution<int> integers{ 0, 20 };

----
Here, we create a generator for number starting at 0 and ending at 20 (20 being
included). Very straightforward indeed ! I'd like to see this feature in future
versions of POVRay in the SDL this time. Since POVRay is written in C++ that
might not be that hard to implement. For instance, unless I missed something,
generating pseudo random numbers, is less convenient while being not so
complicated (and if you need Random number from 0 to 1 only that even is a piece
of cake).
One handy solution I use so far for my needs is the following macro in POVRay
SDL:
----
#macro AffineSet( PointA, PointB, CurrentX )
    #if( PointA.x = PointB.x )
        #error "Can't render, because both x coordinates have equal values"
    #end

 #local DirCoef = (PointB.y - PointA.y) / ( PointB.x - PointA.x );
 #local OriginOffset = PointA.y - (DirCoef * PointA.x);
 (DirCoef * CurrentX) + OriginOffset;
#end

----
This macro returns the Y coordinates of a point in the given interval of point A
and B while taking care of A and B not having the same x axis coordinates.


Post a reply to this message

Copyright 2003-2021 Persistence of Vision Raytracer Pty. Ltd.