Faster random binary number generator

Moderators: Disciple, zlovatt

Post Reply
3deyes
Posts: 4
Joined: May 4th, 2007, 9:25 pm

I have seen various tutorials for gererating random binary numbers including one on Creativecow.net by Dan Ebberts "random hex grid"
http://www.creativecow.net/articles/ebb ... ndex2.html
The problem is speed if you want any more than a few lines of text. Of course they will all play back at 29.97 fps after the preview has been compiled but during that process they are extremely slow.The Creative cow tutorial ran at 1.0 fps and my system has dual 2.0ghz Opterons with 2Gb ram and the O.S on two Seagate drives in raid 0 with two more of the same for playback.I have read about flipped loops with optimized reverse counting and various tutorials on using a StringBuffer function and using switch instead of if statements.I have come up with the following but it still only runs at 1.5 fps. :( The final version even has unnecessary tabs and spaces removed. I still need to make it hold for 5 frames maybe that will speed it up. How can I do that?
Or maybe a different approach by using a varation of this tutorial. http://aefreemart.com/2006/09/13/ae-captions/

Code: Select all

function get_random() {
 var rn=Math.floor(random()*2);
 return rn;
}
function StringBuffer() { 
   this.buffer = []; 
}
 StringBuffer.prototype.append = function append(string) { 
   this.buffer.push(string); 
   return this; 
}
 StringBuffer.prototype.toString = function toString() { 
   return this.buffer.join(""); 
 } 
var j=("\r"),i=1559,buf=new StringBuffer();
do
{
switch (true)
{
case (i%130==0):buf.append(j);break;
default:buf.append(get_random());
}
}
while (--i)
text.sourceText=buf.toString();
[/url]
Last edited by 3deyes on May 8th, 2007, 1:14 pm, edited 1 time in total.
nab
Posts: 203
Joined: November 29th, 2005, 3:00 am
Location: Royan
Contact:

I'm not sure it's faster but you could try the following source text expression:

Code: Select all

numRows = 10;
numCols = 30;
str = "";

for (i = 0; i < numRows; i++) {
   for (j = 0; j < numCols; j++) {
      str += Math.round(random());
   }
   str += "\r";
}  
str;
3deyes
Posts: 4
Joined: May 4th, 2007, 9:25 pm

Ran at 1.3 Fps. For loops and the + operater for string conjugation are just too slow. But thanks anyway.I think what's needed is a faster lower level language. I wish Adobe would take note of how Autodesk added support for Phyton in Maya 8.5. Anyway, do you know how I make it hold for 5 frames?
nab
Posts: 203
Joined: November 29th, 2005, 3:00 am
Location: Royan
Contact:

how I make it hold for 5 frames
The easiest way is probably to use posterizeTime() (at the beginning of the code).
In a 25fps comp:

Code: Select all

posterizeTime(5);
3deyes
Posts: 4
Joined: May 4th, 2007, 9:25 pm

Yes, posterizeTime(5); works thank you. Still the same 1.5 fps though.
Dan Ebberts
Posts: 320
Joined: June 26th, 2004, 10:01 am
Location: Folsom, CA
Contact:

This generates a 128x12 random binary block that seems to render quite a bit faster than other methods:

Code: Select all

s = "";
for (j = 1; j <= 12; j++){
  for (i = 1; i <= 4; i++) s += (4294967296 + Math.floor(random(4294967296))).toString(2).substr(1);
  s += "\r";
}
Dan
3deyes
Posts: 4
Joined: May 4th, 2007, 9:25 pm

It ran a little faster, 1.6 fps. Interesting code though thanks.
Post Reply