Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion. Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 Doom9's Forum Generate a random number
 Register FAQ Calendar Search Today's Posts Mark Forums Read

 21st April 2018, 21:14 #1  |  Link wthreex Registered User   Join Date: Oct 2015 Posts: 43 Generate a random number Is there any function for generate random number in avisynth ?
 21st April 2018, 21:20 #2  |  Link ChaosKing Registered User   Join Date: Dec 2005 Location: Germany Posts: 524 __________________ Search and denoise
21st April 2018, 21:48   #3  |  Link
wthreex
Registered User

Join Date: Oct 2015
Posts: 43
Quote:
 Originally Posted by ChaosKing http://avisynth.nl/index.php/Internal_functions#Rand
Thanks, What is the syntax if i want to use generate align position ?

Code:
`Subtitle("Hello world!", align= rand(9))`
I tried it , But Hello World only goes on the middle video and doesn 't change and every time it makes a same value...

Last edited by wthreex; 21st April 2018 at 21:55.

 21st April 2018, 22:48 #4  |  Link ChaosKing Registered User   Join Date: Dec 2005 Location: Germany Posts: 524 try seed=true. With seed=false it did change 1-2 times, but even after restarting the vdub it stayed at 5. So maybe it's a bug? This works much better Code: ```r=rand(max=9, seed=true) version() Subtitle(String(r), align= round(r))``` __________________ Search and denoise
 22nd April 2018, 00:44 #5  |  Link StainlessS HeartlessS Usurer     Join Date: Dec 2009 Location: Over the rainbow Posts: 6,286 Code: ```#r=rand(max=9, seed=true) # Int, Range 0 to 8, no good (result is modulo 9) r=rand(max=9,seed=true)+1 # Int, Range 1 to 9 version() Subtitle(String(r), align=r) # Align=0, is illegal``` EDIT: Might be better for some requirements Code: ```rand(seed=true) # One time Randomize() # r=rand(max=9)+1 # Int, Range 1 to 9 version() Subtitle(String(r), align=r) # Align=0, is illegal``` __________________ I sometimes post sober. StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace "Some infinities are bigger than other infinities", but how many of them are infinitely bigger ??? Last edited by StainlessS; 25th April 2018 at 20:04.
 25th April 2018, 15:35 #6  |  Link wthreex Registered User   Join Date: Oct 2015 Posts: 43 Thanks.
 25th April 2018, 18:22 #7  |  Link Emulgator Big Bit Savings Now !     Join Date: Feb 2007 Location: close to the wall Posts: 683 Code: ```#r=rand(max=9, seed=true) # Int, Range 0 to 8, no good (result is modulo 9) r=rand(max=9,seed=true)+1 # Int, Range 1 to 9 version() Subtitle(String(r), align=r) # Align=0, is illegal``` r=rand(max=8,seed=true)+1 # Int, Range 1 to 9 version() Subtitle(String(r), align=r) # Align=0 is illegal, 10 too. In the end to have a randomly moving watermark, rand would have to be evaluated for every frame, and position be calculated from that, maybe not using align, but this hasn't been asked. __________________ Die toten Augen von Friedrichshain: "Data reduction ? Yep, Sir. We're working on that issue. Synce invntoin uf lingöage..." "To bypass shortcuts and find suffering"...no, it was somehow different... Last edited by Emulgator; 25th April 2018 at 18:26.
25th April 2018, 19:36   #8  |  Link
StainlessS
HeartlessS Usurer

Join Date: Dec 2009
Location: Over the rainbow
Posts: 6,286
Quote:
 r=rand(max=8,seed=true)+1 # Int, Range 1 to 9 version() Subtitle(String(r), align=r) # Align=0 is illegal, 10 too.
Not quite.

Code:
```BINGOS=0
Rand(seed=true)
For(i=1,50) {
r=Rand(Max=8)+1      # Int, range 1 to 8
BINGOS=(r==9)?BINGOS+1:BINGOS
RT_DebugF("%d] %d %s",i,r,r==9?"BINGO":"")
}
RT_DebugF("\nNumber of 9's = %d",BINGOS)

return version```
Code:
```00000005    1.23400939  RT_DebugF: 1] 2
00000006    1.23405778  RT_DebugF: 2] 7
00000007    1.23410249  RT_DebugF: 3] 1
00000008    1.23414886  RT_DebugF: 4] 4
00000009    1.23418772  RT_DebugF: 5] 6
00000010    1.23423040  RT_DebugF: 6] 7
00000011    1.23427629  RT_DebugF: 7] 5
00000012    1.23431504  RT_DebugF: 8] 8
00000013    1.23435771  RT_DebugF: 9] 2
00000014    1.23440421  RT_DebugF: 10] 5

...

00000044    1.23567069  RT_DebugF: 40] 4
00000045    1.23570931  RT_DebugF: 41] 8
00000046    1.23575175  RT_DebugF: 42] 1
00000047    1.23579741  RT_DebugF: 43] 4
00000048    1.23583603  RT_DebugF: 44] 6
00000049    1.23587847  RT_DebugF: 45] 4
00000050    1.23592424  RT_DebugF: 46] 4
00000051    1.23596275  RT_DebugF: 47] 2
00000052    1.23600531  RT_DebugF: 48] 4
00000053    1.23605096  RT_DebugF: 49] 2
00000054    1.23608959  RT_DebugF: 50] 5
00000055    1.23612595  RT_DebugF:
00000057    1.23616958  RT_DebugF: Number of 9's = 0```
nuther one
Code:
```ColorBars.KillAudio.ShowFrameNumber
Rand(seed=true) # seed only once (As 'Randomize()' in other languages)
Global BINGOS=0
SSS="""
n=current_frame
r=rand(max=9)+1  # Int, Range 1 to 9
Global BINGOS=(r==9)?BINGOS+1:BINGOS
RT_DebugF("%d] %d",n,r)
Subtitle(String(n,"%.0f]")+String(BINGOS," BINGOS=%.0f : ")+String(r,"R=%.0f"), align=r) # Align=0, is illegal
return last
"""
return ScriptClip(SSS)```
EDIT: Results of Rand(max) are modulo max. [The remainder after SomeBigNumber / max]
Quote:
 Rand Rand([int max] [, bool scale] [, bool seed]) Returns a random integer value. All parameters are optional. max sets the maximum value+1 (default 32768) and can be set negative for negative results. It operates either in scaled or modulus mode (default scale=true only if Abs(max) > 32768, false otherwise).
Code:
```Rand(max=n)   # Range 0 to n-1
Rand(max=n)+1 # Range 1 to n```
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 25th April 2018 at 19:58.

 Tags avisynth, function, number, random