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.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Usage

Reply
 
Thread Tools Search this Thread Display Modes
Old 21st April 2018, 21:14   #1  |  Link
wthreex
Registered User
 
Join Date: Oct 2015
Posts: 97
Generate a random number

Is there any function for generate random number in avisynth ?
wthreex is offline   Reply With Quote
Old 21st April 2018, 21:20   #2  |  Link
ChaosKing
Registered User
 
Join Date: Dec 2005
Location: Germany
Posts: 1,795
http://avisynth.nl/index.php/Internal_functions#Rand
__________________
AVSRepoGUI // VSRepoGUI - Package Manager for AviSynth // VapourSynth
VapourSynth Portable FATPACK || VapourSynth Database
ChaosKing is offline   Reply With Quote
Old 21st April 2018, 21:48   #3  |  Link
wthreex
Registered User
 
Join Date: Oct 2015
Posts: 97
Quote:
Originally Posted by ChaosKing View Post
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.
wthreex is offline   Reply With Quote
Old 21st April 2018, 22:48   #4  |  Link
ChaosKing
Registered User
 
Join Date: Dec 2005
Location: Germany
Posts: 1,795
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))
__________________
AVSRepoGUI // VSRepoGUI - Package Manager for AviSynth // VapourSynth
VapourSynth Portable FATPACK || VapourSynth Database
ChaosKing is offline   Reply With Quote
Old 22nd April 2018, 00:44   #5  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
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.
StainlessS is offline   Reply With Quote
Old 25th April 2018, 15:35   #6  |  Link
wthreex
Registered User
 
Join Date: Oct 2015
Posts: 97
Thanks.
wthreex is offline   Reply With Quote
Old 25th April 2018, 18:22   #7  |  Link
Emulgator
Big Bit Savings Now !
 
Emulgator's Avatar
 
Join Date: Feb 2007
Location: close to the wall
Posts: 1,531
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.
__________________
"To bypass shortcuts and find suffering...is called QUALity" (Die toten Augen von Friedrichshain)
"Data reduction ? Yep, Sir. We're that issue working on. Synce invntoin uf lingöage..."

Last edited by Emulgator; 25th April 2018 at 18:26.
Emulgator is offline   Reply With Quote
Old 25th April 2018, 19:36   #8  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
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.
StainlessS is offline   Reply With Quote
Reply

Tags
avisynth, function, number, random

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 16:09.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.