Libraries & objects
About Archicad and BIMcloud libraries, their management and migration, objects and other library parts, etc.

Random numbers in 2d script

fuzzytnth3
Booster
Hi all

I'm trying to write a script for an object that will display random/different people in 2d for elevation drawings. Problem is that the random numbers that ArchiCAD generates are generally the same and not very random!

Is there some way I can force ArchiCAD to generate better random numbers?

I remember writing a programme for my Psion that used random numbers and the best way it did it was getting the time in seconds and multiply that with a "random" number and then get the interger of that result. This was due to the Psion generating somewhat limited random numbers.

Below is the script which calls up a Fragment based on the random number.

10:
Randper= INT (RND (15))
fill bft
pen bpn
fragment2 Randper,1
RETURN
AC versions 3.41 to 25 (UKI Full 5005).
Using AC25 5005 UKI FULL
Mac OSX 10.15.7 (19G2021) Mac Pro-2013 32gbRam AMD FirePro D500 3072 MB graphics
30 REPLIES 30
Karl Ottenstein
Moderator
fuzzytnth3 wrote:
Karl wrote:
I used my goofy function for the ArchiContest a few years ago where I built a Finnish Tulikivi soapstone fireplace that was a light source for the scene - and the firelight flickered randomly in intensity, direction and color (within limits of course to make it look real). It used 3 AC lamps inside the woodstove to get the desired effect, which was pretty cool. I think I still have a little MOV that I could post if anyone is interested.
That sounds very cool. Do you still have the animation on the web somewhere? I would love to see it.
Just uploaded the small QuickTime movie (182 kb) to:
http://www.archispectives.com/tips/Flickering-Firelight-Karl.mov

Low quality res and scene was just to demo the firelight.

Thanks,
Karl
One of the forum moderators
AC 28 USA and earlier   •   macOS Sequoia 15.2, MacBook Pro M2 Max 12CPU/30GPU cores, 32GB
fuzzytnth3
Booster
Just uploaded the small QuickTime movie (182 kb) to:
http://www.archispectives.com/tips/Flickering-Firelight-Karl.mov

Low quality res and scene was just to demo the firelight.

Thanks,
Karl
Very effective Karl.

I finished my random people object yesterday. I've attached a wee snapshot. Quite chuffed with it as it works on slopes as well as horizontal
AC versions 3.41 to 25 (UKI Full 5005).
Using AC25 5005 UKI FULL
Mac OSX 10.15.7 (19G2021) Mac Pro-2013 32gbRam AMD FirePro D500 3072 MB graphics
Karl Ottenstein
Moderator
fuzzytnth3 wrote:
I finished my random people object yesterday. I've attached a wee snapshot. Quite chuffed with it as it works on slopes as well as horizontal
Very nice. It illustrates nicely one of my broader wishes for GDL: that objects can be aware of their surroundings. There are cases where you have two identical people adjacent to one another in your image. A simple result of randomness. It would be nice if an object were "contextually aware" ... and could make queries such as "if there is an object of type X within Y meters of me, what is the value of parameter Z for that object" (well, actually, it would return a set - or array - of such things). Then, one of the identical people could turn itself into a different image in your case.

More broadly, objects could 'react' to other elements - preventing interferences (if desired), or maintaining specified distances from other elements. A toilet would enforce spacing from walls and cabinets that conforms to building codes, for example. For the dream list, if not the wish list. 😉 😉

Karl
One of the forum moderators
AC 28 USA and earlier   •   macOS Sequoia 15.2, MacBook Pro M2 Max 12CPU/30GPU cores, 32GB
fuzzytnth3
Booster
I was just thinking that while cycling home tonight.

One thought I had was to use an array where you create a random number put it in the array and then generate another random number but then have the script check what the first number was but add an allowance for the width of the first object, in this case a person. If the second random fell within the range of the first then the script would generate a new random number until it creates a random number that doesn't clash with the first. Repeat the process for more iterations.

Having said all that, I thought to myself arrrgh! I have never used arrays in GDL or the PSION language that I used to write programmes for. I have just never quite got my head round how you pull out the specific number from an array that you want to use.

Maybe I should see this as a challenge to conquer arrays
AC versions 3.41 to 25 (UKI Full 5005).
Using AC25 5005 UKI FULL
Mac OSX 10.15.7 (19G2021) Mac Pro-2013 32gbRam AMD FirePro D500 3072 MB graphics
Anonymous
Not applicable
Oleg,

You wrote on April 2:

10:
   Randper= RND(GLOB_INTID) ! pass one random

   ! +1    : fragments index start from 1
   ! -1e-6 : to avoid exactly 16

   Randper= INT(RND(16)-1e-6) + 1
   fill bft
   pen bpn
   fragment2 Randper,1
RETURN

What is the variable "1e" ?
Where is it declared ?

Thanks,
Peter Devlin
Oleg
Expert
Peter wrote:
What is the variable "1e" ?
Where is it declared ?

Thanks,
Peter Devlin
It is not variable.
1e-6 is just a number (small one).
This format available in most programming languages.
It mean power of 10, like 1*10^(-6)
= 0.000001

Oleg.
Anonymous
Not applicable
Thank you Oleg.
I did not know that.

I wrote this in a 3D script

!It is not variable.
!1e-6 is just a number (small one).
!This format available in most programming languages.
!It mean power of 10, like 1*10^(-6)
!= 0.000001

w=0.000001
x=1*10^(-6)
y=1e-6
z=10**(-6)

print w,",",x,",",y,",",z

it printed this: 1e-06,1e-06,1e-06,1e-06

Thank you for this information.
Peter Devlin
Paul King
Mentor
Oleg - you are now my official hero!
Wish I had read your trick many wasted hours ago!

Cheers

Paul
PAUL KING | https://www.prime.net.nz
ArchiCAD 8-28 | Twinmotion 2024
Windoze 11 PC | Intel Core i9 10900K | Nvidia Gforce RTX 3080 | 32 Gb DDR3 | 2x4K monitor extended desktop
They had the same problem with iPod Shuffle. True random was given not the desired random-like-ness, you sometimes got the same song again too soon. So the newer versions do this 'corrected randomness' like you are all talking about.

That random people object looks very cool.
Lingwisyer
Guru
Can this be made to work in Custom Door Leafs and Custom Window Sashes? Before I commit to linking all of my variables...



Ling.

AC22-23 AUS 7000Help Those Help You - Add a Signature
Self-taught, bend it till it breaksCreating a Thread
Win11 | i9 10850K | 64GB | RX6600 Win10 | R5 2600 | 16GB | GTX1660