Design forum
cancel
Showing results for 
Search instead for 
Did you mean: 

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 4013).
Using AC23 6004 UKI FULL
Mac OSX 10.15.7 (19G2021) Mac Pro-2013 32gbRam AMD FirePro D500 3072 MB graphics
30 REPLIES 30

Matthew Lohden
Newcomer
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?
Matthew Lohden
Consultant, SF CA

MacPro 8core 32GB Radeon 5870
OSX 10.8 Mountain Lion, XP32, Win 7x64

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 4013).
Using AC23 6004 UKI FULL
Mac OSX 10.15.7 (19G2021) Mac Pro-2013 32gbRam AMD FirePro D500 3072 MB graphics

Matthew Lohden
Newcomer
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.
Matthew Lohden
Consultant, SF CA

MacPro 8core 32GB Radeon 5870
OSX 10.8 Mountain Lion, XP32, Win 7x64

Joachim Suehlo
Advocate
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)
Joachim Suehlo . AC12-25 . MAC OSX 10.15 . WIN10

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 4013).
Using AC23 6004 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 4013).
Using AC23 6004 UKI FULL
Mac OSX 10.15.7 (19G2021) Mac Pro-2013 32gbRam AMD FirePro D500 3072 MB graphics

Matthew Lohden
Newcomer
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.
Matthew Lohden
Consultant, SF CA

MacPro 8core 32GB Radeon 5870
OSX 10.8 Mountain Lion, XP32, Win 7x64

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 4013).
Using AC23 6004 UKI FULL
Mac OSX 10.15.7 (19G2021) Mac Pro-2013 32gbRam AMD FirePro D500 3072 MB graphics

Oleg
Advocate
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

Matthew Lohden
Newcomer
Oleg wrote:
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
Interesting trick. I have always wondered what the internal ID might be useful for.
Matthew Lohden
Consultant, SF CA

MacPro 8core 32GB Radeon 5870
OSX 10.8 Mountain Lion, XP32, Win 7x64

Oleg
Advocate
fuzzytnth3 wrote:
10:
Randper= INT (RND (15))
fill bft
pen bpn
fragment2 Randper,1
RETURN
Try this
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 

fuzzytnth3
Booster
Thanks Oleg that did the trick
AC versions 3.41 to 25 (UKI Full 4013).
Using AC23 6004 UKI FULL
Mac OSX 10.15.7 (19G2021) Mac Pro-2013 32gbRam AMD FirePro D500 3072 MB graphics

James B
Graphisoft
Graphisoft
I've found this useful as well. Thanks

I've made a part that forms planks of varying widths, though I've got a few issues:

When I copy my object, the projection on plan is the same as the original, even though when I go to 3D view the objects apear different.

Any ideas how to get around this?

And while I'm at it, how do I get the 3D and 2D script to use the same random number sequence? So I get hotspots on each end of the plank.

Thanks.
Technical Product Manager, Graphisoft

Matthew Lohden
Newcomer
James wrote:
I've found this useful as well. Thanks

I've made a part that forms planks of varying widths, though I've got a few issues:

When I copy my object, the projection on plan is the same as the original, even though when I go to 3D view the objects apear different.

Any ideas how to get around this?

And while I'm at it, how do I get the 3D and 2D script to use the same random number sequence? So I get hotspots on each end of the plank.

Thanks.
Try generating your random values in the master script.
Matthew Lohden
Consultant, SF CA

MacPro 8core 32GB Radeon 5870
OSX 10.8 Mountain Lion, XP32, Win 7x64

James B
Graphisoft
Graphisoft
I tried that. But because each plank needs to be random widths, the random number is generated with in a FOR NEXT 3D script - therefore generating a new random number for each plank.
Technical Product Manager, Graphisoft

Bill Rattenbury
Newcomer
James wrote:
I tried that. But because each plank needs to be random widths, the random number is generated with in a FOR NEXT 3D script - therefore generating a new random number for each plank.
In the master script you could get it to create an array and fill it with random numbers, then use these same numbers sequentially in both scripts as part of a FOR NEXT loop.

regards
Bill Rattenbury
BArch|ANZIA|AC18

Karl Ottenstein
Moderator
Hi guys,

Just got home from ACUWest trip last night and am slowly catching up here. A number of comments to throw into the soup.

First, we are talking about 'pseudo-random' numbers here - a number sequence that is mathematically generated in a way such that when tested with a variety of statistical tests, it satisfies criteria for appearing random ... yet (this is the key) it is completely reproducible.

Matthew (good meeting you!) is right to a point about the coins and so forth. A mathematical coin when flipped a large number of times (not necessarily approaching infinity!) will be heads 50% of the time and tails 50% of the time. A sequence of 12 numbers is not sufficient to verify the mathematical properties of a random number generator. 100's to 1,000's have to be generated if one really cares (AC's RND is 'good enough') ... and then various tests are run ... a so-called 'bucket' test - throwing the numbers into buckets to make sure that the generator is uniform - that is, it does not favor certain values over others. (For a generator producing numbers from 1 to 10, we might have 10 'buckets' ... and generate 1,000 numbers... and would expect to see close to 100 - perhaps 95 to 105 - numbers in each bucket.) A 'runs' test, makes sure that the generator isn't generating numbers in sequence too often ... 1,2,3,4,5,6,7,8,9,10 over and over would pass the bucket test, but wouldn't be too random. And so forth. A very well-studied area of computer science and statistics for over 50 years dating back to when computer simulations were called 'Monte Carlo' simulatinos. 😉

Anyway, just some more background there. 😉

Attached is a GDL object that displays either a list of numbers or a bar chart (parameter) in 2D. No statistical tests. But, it lets you see some of the numbers produced by the AC RND function. Rebuild and they stay the same. If you select the 'Karl' function (which isn't statistically perfect, but is OK), then when you rebuild, you'll see a different set of numbers each time. This function was created in order to product an animation that DOES change with each rebuild ... so each new frame of a movie has a new effect. Was going to write something up about it for David's Cookbook, but until today, hadn't seen that anybody else was interested in random numbers. 😉

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.

See you in Las Vegas (not).

Karl
One of the forum moderators   •   AC 25 USA and earlier   •   MacOS 11.6.1, iMac Pro

Karl Ottenstein
Moderator
Here's a screenshot of the output of the previous GDL object for a small sequence of numbers (different sequence left and right by the way).

Karl
One of the forum moderators   •   AC 25 USA and earlier   •   MacOS 11.6.1, iMac Pro

fuzzytnth3
Booster
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.

Cheers

Graeme
AC versions 3.41 to 25 (UKI Full 4013).
Using AC23 6004 UKI FULL
Mac OSX 10.15.7 (19G2021) Mac Pro-2013 32gbRam AMD FirePro D500 3072 MB graphics

Didn't find the answer? Start a new discussion

Labels

Still looking?

Browse more topics

Back to forum

See latest solutions

Accepted solutions

Start a new discussion!