Archive: Maths Problem


22nd September 2004 14:13 UTC

Maths Problem
If you have completely different numbers (like in my case 16, 17, 25, 26, 31, 51,), how do you change a variable (on random or sequential) between just these integer numbers?

If the numbers were for example 5,10,15,20, it would be very easy (something like: var = var + 5 * rand(3) set onBeat will be enough).

But in this case.... aaRgh... How do I skip all these unregular "gaps"?

I hope someone can help me solving my little math-riddle...

Thank you!


22nd September 2004 19:06 UTC

I'd use something like:

3 'random' numbers: 3,9,5


var=rand(3);
//where 3 is the amount of variables

var1=equal(var,0)*3+equal(var,1)*9+equal(var,2)*5;
//extend to how much is needed. Quite fast.

Of course you can use variables instead of constants too.

22nd September 2004 21:08 UTC

Yeah, you got it! :up:

And it's so simple..

Thank you! :)


23rd September 2004 15:31 UTC

No problem

ps: love your signature


24th September 2004 16:49 UTC

I'm sorry but that solution is manky icky and horrible...

use the megabuffer inniiiit, say you have 5 numbers you want to change between

init:

assign(megabuf[0],1);
assign(megabuf[1],3);
assign(megabuf[2],6);
assign(megabuf[3],7);
assign(megabuf[4],11);

then when you need the number:

currentval=megabuf[index];

cycling sequentially:

index=(index+1)%5;

....randomly:

index=rand(5);

my syntax might be a bit wrong (I'm not in front of winamp) but you get the idea.


25th September 2004 00:14 UTC

megabuf the way the to go.
You can use it to easily make and change what numbers you want it to put out and you can easily make it global using gmegabuf.


25th September 2004 08:20 UTC

This sounds good too! The point, that gmegabuf can be globaly used in the whole presets also brings an advantage.
But the use of the megabuf ends up in a slightly bigger expression. And indeed warrior's term does give me the solution i need. The ssc i used it with works the way i wanted it to. So why is it an advantage to use the megabuf, when avs-code should be as short as possible?

Have a look at what i used it for:

<http://forums.winamp.com/showthread....hreadid=194437>


25th September 2004 12:19 UTC

AVS code is not ment to be as short as possible, but as fast as possible and from what i've hear megabuf (or the g version of it) is faster to use than what regular AVS means prior to 2.7.

But what would i know, i don't use megabuf because i can't understand that shitznazz :p


25th September 2004 19:53 UTC

I don't really know faster or not, but it would probably require more lines of code to input the variables. Since you just want the output numbers to be static, you can have them be set on init, so that shouldn't be a fps problem. Once you get into the actual preset it should be close enough to the same fps that you couldnt tell a difference, in fact, megabuf might even be a hair faster, becuase both methods are doing basically the same way to get the random number, one just uses the megabuf to load the values while the other uses a multiplier, so theoretically, the megabuf one should be faster because it has less operations.


25th September 2004 22:41 UTC

I think, i agree with tuggummi: use the kind of code you understand! On one hand the meagbuf thing seems to be not that difficult, but on the other I completely understand the math behind the first code thing. Also, if it's not a big difference in fps, it will be a decision of favour... ;)


27th September 2004 17:13 UTC

var=1;
result=equal(var,index)*number;

is slower than

var=1;
result=gmegabuf[var];

because you have at least 1 equal and a multiplication. Furthermore the previous method gets linearly slower the more numbers you have to pick from. My methodtm does not get any slower even with a million numbers because they are cached into the (g)megabuf on init.

pwnt


27th September 2004 20:48 UTC

i'm just about understanding the point with speed: it's a question of how many calculations avs has to make; the more the slower it gets. on the opposite you can write an essay about your last holidays and use it as an variable (as long as you don't use spaces) for example.
However you write the code in this example, there will probably always be another way to do. Thats the point why we all love avs, isnt't it? The only limitation is your imagination (and fps, of course.. ;))


27th September 2004 22:27 UTC

on the opposite you can write an essay about your last holidays and use it as an variable
Hmm, not quite. Any variable longer than 8 letters will be discarded. This means that you can still write long variables yes, but longcode1 is the exact same as longcode2 since it doesn't count anything beyond the letter 'e' which is the 8th letter in both of them.

'wantmoredownloads' is really just
'wantmore' in the eyes of avs :)

29th September 2004 18:10 UTC

Originally posted by Tuggummi
Hmm, not quite. Any variable longer than 8 letters will be discarded. This means that you can still write long variables yes, but longcode1 is the exact same as longcode2 since it doesn't count anything beyond the letter 'e' which is the 8th letter in both of them.

'wantmoredownloads' is really just
'wantmore' in the eyes of avs :)
Well actually you could cache the variable name into the megabuf on init using acsii codes and a control character to represent the termination of the variable name. Then reference the first item of the variable name, add up the codes that make the variable name and apply a hashing algorithm to turn it into a unique number representing a point in the megabuffer where the variable is stored (probably 1,000,000 minus the result to avoid conflict with the variable names). Simple really.

:D :D :D ;)

go on, give me another one ;)

29th September 2004 21:04 UTC

...ehm... :confused: i just tried to give a stupid example, to see whether i understood this fast-code-slow-code part or not.
Since it wasn't supposed to become a specialists discussion, nevertheless it's nice to see what way my actual question has gone. (what was i asking for anyway? :D)
However i think i got the answer (and more).

PS: Is this what one call "offtopic"? ;)


29th September 2004 21:14 UTC

Originally posted by PAK-9
go on, give me another one ;)
o.k. i have another one for you:
If i use your method to name a variable or anything else after my essay about last holidays, i will be able to use spaces and all other characters. But is your method capable to format my cute little story in paragraphs and so on? How would you do that, hm? ;)

30th September 2004 17:20 UTC

Oh thats simple you just take a formatting standard or a file structure. You could use the rich text format which uses a series of control characters for example. However if it was me I'd go for a standard like html, where you would brace formatting characters like [b], it would require 3 or more megabuf elements per control character which is quite expensive; however the html format would let you define all sorts a zany variable names, like web pages with text and pictures :D :D :D


30th September 2004 18:31 UTC

If you go on with this nonsense you perhaps should write a book: "The thinking fridge or How my kitchen got controlled by AVS". You'll have at least one buyer for sure! :D:p:D


30th September 2004 22:03 UTC

Naah, i think PAK-9 is just pullin yer leg in this ;)

I mean, even if it is truely possible to do such things, why on earth would you do it anyway? :p


30th September 2004 23:22 UTC

i know it's all just for fun. :p

though, since mobile phones aren't used for phone calls only anymore, who can predict what additional functions other things will have in future.. ;)
So it's kind of market research.. :D :D


1st October 2004 16:12 UTC

Yea I'm not sure why you would want an entire formatted web page as a variable name, but I can assure you my method is sound.

mmmm....AVS fridge


3rd October 2004 17:16 UTC

AVS Fridge.

LMAO!
:blah::D:)


3rd October 2004 22:51 UTC

The best thing about it is surely the "dynamic movement".

If your fridge is empty it will dynamical move to the next supermarket and buy new food, beer, or whatever.:cool:


3rd October 2004 23:25 UTC

eeh, im thinking of another "fridge"...

nevermind...


4th October 2004 00:27 UTC

err... sorry, my english isn't that good (as you may have seen already).:(
Didn't knew that "fridge" also means something different than "place-to-put-food-in-to-stay-cold"...:confused:


4th October 2004 23:06 UTC

Well it doesn't... it's just a inside joke thing :)

Which im not arsed to explain about, so you're shit out of luck :P


4th October 2004 23:40 UTC

Of course you won't.
if you explained it to me, it wouldn't be an insider-thing anymore...:)


5th October 2004 00:23 UTC

Nope, the whole world would know it.