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
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.
Oleg
Expert
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 5005).
Using AC25 5005 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.
James Badcock
Graphisoft Senior Product Manager
Anonymous
Not applicable
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.
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.
James Badcock
Graphisoft Senior Product Manager
Anonymous
Not applicable
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
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 28 USA and earlier   •   macOS Sequoia 15.2, MacBook Pro M2 Max 12CPU/30GPU cores, 32GB
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 28 USA and earlier   •   macOS Sequoia 15.2, MacBook Pro M2 Max 12CPU/30GPU cores, 32GB
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 5005).
Using AC25 5005 UKI FULL
Mac OSX 10.15.7 (19G2021) Mac Pro-2013 32gbRam AMD FirePro D500 3072 MB graphics