POV-Ray : Newsgroups : povray.pov4.discussion.general : Improve Random number generation in future versions of POVRay Server Time
29 Mar 2024 07:43:01 EDT (-0400)
  Improve Random number generation in future versions of POVRay (Message 1 to 3 of 3)  
From: Warren
Subject: Improve Random number generation in future versions of POVRay
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

From: Saul Luizaga
Subject: Re: Improve Random number generation in future versions of POVRay
Date: 16 Jun 2021 09:00:31
Message: <60c9f5ef$1@news.povray.org>
I watched a few 'Grill the Committee' videos and 1 was for C++20 and 
were talking about new RNG, I made a Google search and found these 2 
sites that might be of interest:
https://www.softwaretestinghelp.com/random-number-generator-cpp/
https://en.cppreference.com/w/cpp/numeric/random
Book: Options and Derivatives Programming in C++20 
https://link.springer.com/book/10.1007%2F978-1-4842-6315-0
IHIH (I Hope It Helps)


Post a reply to this message

From: Saul Luizaga
Subject: Re: Improve Random number generation in future versions of POVRay
Date: 16 Jun 2021 09:20:40
Message: <60c9faa8$1@news.povray.org>
On 16/06/2021 9:00, Saul Luizaga wrote:
> Options and Derivatives Programming
Chapter 13,  Random Number Generation, Page 319


Post a reply to this message

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