Monday
some simple randomization algorithm in GDL to get the value 1 or -1 ? 🙂
Solved! Go to Solution.
Monday
There is a random function in GDL (RND), but it returns a positive number.
You would have to do something like this I would think...
if RND(1) <= 0.5 then
my_value = -1
else
my_value = 1
endif
Barry.
Wednesday - last edited Wednesday
thanks Barry, this is a very old post but the idea is right,
except that GLOB_INTID is now probably GLOB_INTGUID.
And GLOB_INTGUID is a string and I think you should randomly choose a number (or letter) from it. And I used this fact (letter or number) as a trick for the -/+1 situation (i.e. the direction of decreasing or increasing the constant size of the base object).
Finally, something like this came out:
... myscript
q=strsub(GLOB_INTGUID,int(RND(10)),1) !!! STR random number [0-9] or letter from object GLOB_INTGUID
id2int=0 : n = SPLIT (q, "%n", id2int) !!! convert STR 2 INT
xdir= ( (id2int<EPS)*(-1) + (id2int>EPS)*(1) ) !!! if letter= -1, if number= +1
!!! default size
aa=A
bb=B
hh=ZZYZX
if rnd_size then !!! if random object sizes ON
if rnd_a>EPS then \ !!! if random object size A
aa = A + RND ((rnd_a - id2int) *0.01 ) * xdir !!! if random A, rnd_a=myrange [0,....]
if rnd_b>EPS then \ !!! if random object size B
bb = B + RND ((rnd_b - id2int) *0.01 ) * xdir !!! if random B, rnd_b=myrange [0,....]
if rnd_h>EPS then \ !!! if random object size ZZYZX
hh = ZZYZX + RND ((rnd_h - id2int) *0.01 ) * xdir !!! if random ZZYZX, rnd_h=myrange [0,....]
endif
...model hedge aa x bb x hh
Control of the range of increasing/decreasing dimensions AxBxZZYZX is done with separate parameters rnd_a, rnd_b, rnd_h. Setting e.g. rnd_a=0 means using the base dimension A.
And generally speaking, in my specific application it is not a "bug" that random numbers are "constant", because I do not want objects to randomly change their dimensions with each window regeneration. It would be bad if a given hedge in one camera shot had for example a different height, and in another camera shot (or section/elevation...) a different one. That would be ridiculous! The random dimensions will actually change only after changing the base AxBxZZYZX (OR AFTER CLONING the object!).
 
Monday
There is a random function in GDL (RND), but it returns a positive number.
You would have to do something like this I would think...
if RND(1) <= 0.5 then
my_value = -1
else
my_value = 1
endif
Barry.
Monday
And from memory it is not truly random.
You will get the same result every time you run it.
Barry.
Monday
Barry thanks, I know rnd() but it's a weird function.
I thought to use REQUEST('DateTime'... but it's not possible to read at least milliseconds etc.
Tuesday - last edited Tuesday
I have used the RND function in conjunction with a position variable of the relevant entity before. Use the % operand to "limit" the output to your desired range.
mat_array[int(rnd(abs(mat_seed*iDis)) % mat_count) + 1]
If I want a different generation, I can just change the seed if I do not want to change the position.
ps. What are you trying to do that needs to be randomised every milisecond? There's not Unix time stamp in AC...
AC22-28 AUS 3110 | Help Those Help You - Add a Signature |
Self-taught, bend it till it breaks | Creating a Thread |
Win11 | i9 10850K | 64GB | RX6600 | Win11 | R5 2600 | 16GB | GTX1660 |
Tuesday
Thank you @Lingwisyer
1. I have several hedges with the SAME dimensions A,B,ZZYZX e.g. 100x60x150
2. In gdl (without changing A,B,ZZYZX) I would like each hedge to add to A,B,ZZYZX (or subtract) a random value from the range e.g. 0-10cm.
3. This way each hedge will look slightly different (a little longer or shorter, a little wider or narrower, a little higher or lower etc.).
aa=A
bb=B
hh=ZZYZX
if rnd_size then
if rnd_a>EPS then aa=aa+rnd(10)*rnd_a*0.01 !!! if random A, rnd_a=<0,1,2...>
if rnd_b>EPS then bb=bb+rnd(10)*rnd_b*0.01 !!! if random B, rnd_b=<0,1,2...>
if rnd_h>EPS then hh=hh+rnd(10)*rnd_h*0.01 !!! if random ZZYZX, rnd_h=<0,1,2...>
endif
...model hedge aa x bb x hh
For now I can randomly increase A,B,ZZYZX, that's why I asked about random +/-1
 
Tuesday
Another possibility
xx = 0.50
my_value = -xx + RND(xx*2)
Wednesday
Need to work on your pruning skills!
Are you just wanting the ±1 to mirror your output values into the negatives? Just double the size of your RND range and offset everything. As Barry has mentioned, every instance of RND in your script will return the same base value, so in your case your range would end up split in half. It is why the code that I showed before uses a position value as it is something that would change enough with each loop to faux the randomisation. The seed value then just makes this faux even more obscure. Without it I would have gotten a very visible set pattern.
Ling.
AC22-28 AUS 3110 | Help Those Help You - Add a Signature |
Self-taught, bend it till it breaks | Creating a Thread |
Win11 | i9 10850K | 64GB | RX6600 | Win11 | R5 2600 | 16GB | GTX1660 |
Wednesday
I found this post that may help to generate non-repeating random numbers.
You can read the whole thread but from the post I link to I think is most relevant.
It is all about generating a unique seed.
Barry.
Wednesday - last edited Wednesday
thanks Barry, this is a very old post but the idea is right,
except that GLOB_INTID is now probably GLOB_INTGUID.
And GLOB_INTGUID is a string and I think you should randomly choose a number (or letter) from it. And I used this fact (letter or number) as a trick for the -/+1 situation (i.e. the direction of decreasing or increasing the constant size of the base object).
Finally, something like this came out:
... myscript
q=strsub(GLOB_INTGUID,int(RND(10)),1) !!! STR random number [0-9] or letter from object GLOB_INTGUID
id2int=0 : n = SPLIT (q, "%n", id2int) !!! convert STR 2 INT
xdir= ( (id2int<EPS)*(-1) + (id2int>EPS)*(1) ) !!! if letter= -1, if number= +1
!!! default size
aa=A
bb=B
hh=ZZYZX
if rnd_size then !!! if random object sizes ON
if rnd_a>EPS then \ !!! if random object size A
aa = A + RND ((rnd_a - id2int) *0.01 ) * xdir !!! if random A, rnd_a=myrange [0,....]
if rnd_b>EPS then \ !!! if random object size B
bb = B + RND ((rnd_b - id2int) *0.01 ) * xdir !!! if random B, rnd_b=myrange [0,....]
if rnd_h>EPS then \ !!! if random object size ZZYZX
hh = ZZYZX + RND ((rnd_h - id2int) *0.01 ) * xdir !!! if random ZZYZX, rnd_h=myrange [0,....]
endif
...model hedge aa x bb x hh
Control of the range of increasing/decreasing dimensions AxBxZZYZX is done with separate parameters rnd_a, rnd_b, rnd_h. Setting e.g. rnd_a=0 means using the base dimension A.
And generally speaking, in my specific application it is not a "bug" that random numbers are "constant", because I do not want objects to randomly change their dimensions with each window regeneration. It would be bad if a given hedge in one camera shot had for example a different height, and in another camera shot (or section/elevation...) a different one. That would be ridiculous! The random dimensions will actually change only after changing the base AxBxZZYZX (OR AFTER CLONING the object!).