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
Anonymous
Not applicable
Random numbers in ArchiCAD are (AFAIK) only generated once, i.e. when an object is first placed. This avoids strangely animated trees in flythroughs that rebuild the model for each frame.

You can, as you suggest, come up with your own random number code or you could delete and replace your library part for each random iteration.

The only thing is, people don't arrange themselves randomly, you are probably in for some goofy results. Oh, I get it (I think) it's not random arrangements you are looking for just random characters?
fuzzytnth3
Booster
Matthew wrote:
Oh, I get it (I think) it's not random arrangements you are looking for just random characters?
Yep that's right. The idea is each time you insert the object into the drawing you get a different person displayed.

Basically I'm lazy and hate making decisions I don't want to have to keep selecting a different person myself I want the object to do it for me

So I think from what you saying that I will need to find away to script the random number so it's more random than what ArchiCAD is coming up with.
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
There is also the question of what you mean by random. True randomness does not typically produce an even distribution. It is just as likely that flipping a coin will get you twenty heads in a row as it will an alternation between heads and tails or any other specific result. What you may be looking for is to introduce a small randomness into an otherwise sequential order.
Jochen Suehlo
Moderator
Hi,
I have a problem similar to the Subject:

In an object the random calculation seems to be taken twice.
The first for the 3D-Script and the second for the PROJECT2 command in the 2D-Script.
How can this be?
See the pictures below: the colored is a snapshot of the 3D-window,
the non colored is a snapshot of the 2D-window where the object is shown with a PROJECT2-coomand.
(The object shows a brick girder from below; the place of the short bricks is calculated by random)
Jochen Suehlo . AC12-27 . MAC OSX 14.4 . WIN11
GDL object creation: b-prisma.de
fuzzytnth3
Booster
RND does let you set a limit to the range that the RND command will generate.

So in my example it should generate a number greater than 0 but not greater than 12. 12 being the number of fragments I have drawn diffeerent people on. Sadly it just keeps producing the number

I tried using the REQUEST command to find out the time in seconds but have discovered that the REQUEST command produces a text string even although it looks like numbers
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
fuzzytnth3
Booster
Joachim wrote:
Hi,
I have a problem similar to the Subject:

In an object the random calculation seems to be taken twice.
The first for the 3D-Script and the second for the PROJECT2 command in the 2D-Script.
How can this be?
See the pictures below: the colored is a snapshot of the 3D-window,
the non colored is a snapshot of the 2D-window where the object is shown with a PROJECT2-coomand.
(The object shows a brick girder from below; the place of the short bricks is calculated by random)
Do you have the RND function in the Master script? If it is in both the 3d and 2d scripts then it should give a different result each time.

Least you are getting more "randomness" than me
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
I just tried the RND function and it seems to be working as expected:

Define style text_style `Arial`, 3, 1, 0
Style text_style

FOR i = 1 TO 12
Text2 0, 0, INT(RND(12))
add2 0, -0.006*GLOB_SCALE
NEXT i


This produced the attached...

A fairly typical random sequence between 0 and 12.
RND example.jpg
fuzzytnth3
Booster
Thanks for trying that. I took your script and tried it as an object and what I found was that it does generate random numbers but if you insert the object again it produces exactly the same numbers.

What I did find was that when you close and open the drawing again all the numbers change but all the instances of the object still display the same numbers.

So to get the random People in my object to work I would have to insert one instance of the object but have a number of random People appear like your script and I suppose I could also place each Person in a random position similar to Joachim's object. Sounds like this would be an even easier way put some People in my drawing
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
Oleg
Expert
fuzzytnth3 wrote:
Thanks for trying that. I took your script and tried it as an object and what I found was that it does generate random numbers but if you insert the object again it produces exactly the same numbers.
I think, this is some of GDL engine optimization effect.
Try this trick to avoid it.
Instead RND(12) type RND(12 + GLOB_INTID*0 )

Oleg