Board index » cppbuilder » random numbers between 0 and 1
Gerrit
![]() CBuilder Developer |
Gerrit
![]() CBuilder Developer |
random numbers between 0 and 12005-02-09 01:05:34 AM cppbuilder103 I'm trying to put a simple idea into code, but I keep getting syntactic errors of one kind or another. The condition I'm trying to code is, in English: IF the absolute value of the difference between two random numbers between 0 and 1 is smaller than a value Maxx, THEN ... Things I've tried; float Maxx; if (abs(random-random) < Maxx) ... float a, b, Maxx; a = random; b = random; if (abs(a-b) < Maxx) ... Gerrit. |
Gerrit
![]() CBuilder Developer |
2005-02-09 01:08:52 AM
Re:random numbers between 0 and 1
On 08 Feb 2005, Gerrit boldly opined:
QuoteI'm trying to put a simple idea into code, but I keep getting syntactic G. |
Duane Hebert
![]() CBuilder Developer |
2005-02-09 01:22:51 AM
Re:random numbers between 0 and 1
"Gerrit" < XXXX@XXXXX.COM >wrote in message
QuoteOn 08 Feb 2005, Gerrit boldly opined: errors. From the code that you show, you're testing abs(0) < Maxx. {smallsort} |
Palle Meinert
![]() CBuilder Developer |
2005-02-09 01:44:11 AM
Re:random numbers between 0 and 1
As Duane already said, i will also suggest to use double instead of float.
Also notice that the random function returns a int, so to get it in the range between 0 and 1 you need to do something along the lines of double RandomNumber = random(Resolution) / Resolution Also be aware that the abs function is for integers and won't work, you should use fabs instead when dealing for floating point. /Palle |
Gerrit
![]() CBuilder Developer |
2005-02-09 02:16:08 AM
Re:random numbers between 0 and 1
On 08 Feb 2005, Palle Meinert wrote:
QuoteAs Duane already said, i will also suggest to use double instead of large value for Resolution will work fine though. Gerrit |
orphan
![]() CBuilder Developer |
2005-02-09 03:22:12 PM
Re:random numbers between 0 and 1
Gerrit < XXXX@XXXXX.COM >wrote:
QuoteThings I've tried; Try "fabs" instead - float version of abs. orphan |