Sg2.9
Fisher-Yates applied to FontR...
Recent RSS
Fisher-Yates applied to FontRhythm
From:  Harry
Date:  3. June 2011, 21:47

For a specific project I've made an edit to the randomize function on the FontRyhthm script so that instead of randomly selecting from all installed fonts (using 'app.fonts') it randomly selects from a predetermined array (in my case, '['Times', 'Helvetica', 'Verdana']'. In its final iteration it will be 50+ specifically selected fonts).

This is all working well, however I now need to make the next step. I'd like it so that it randomly selects from the array of fonts, without selecting the same font twice until it has cycled through the entire array. A bit of googling and I found out that this process is better known as the Fisher-Yates shuffle

I also found this snippet of Fisher-Yates in js.

The edited line in the script currently looks like:

if(values.randomfont){
var array_randomfonts = ['Times', 'Helvetica', 'Verdana'];
var randomFont = array_randomfonts[Math.floor(Math.random()*array_randomfonts.length)];
charRange.characterStyle.font = randomFont;
} else {
charRange.characterStyle.font = fontchoice;
}

Any help or advice on how to apply Fisher-Yates shuffle to this would be great! If more details would be helpful please let me know.

Re: Fisher-Yates applied to FontRhythm
Date:  4. June 2011, 14:55

Declare the array outside the loop:

var array_randomfonts = [];

In the loop:

if (values.randomfont){
	// If the array is empty, populate it again:
	if (array_randomfonts.length == 0) {
		array_randomfonts = ['Times', 'Helvetica', 'Verdana'];
	}
	var index = Math.floor(Math.random() * array_randomfonts.length);
	var randomFont = array_randomfonts[index];
	// Remove the element from the array:
	array_randomfonts.splice(index, 1);
	charRange.characterStyle.font = randomFont; 
} else {
	charRange.characterStyle.font = fontchoice;
}
Re: Fisher-Yates applied to FontRhythm
From:  Harry
Date:  4. June 2011, 21:55

Hey Jonathan, thanks for the quick response. I made the edits and it's working perfectly. Cheers!

Scripts
08.08.14, 15:24
15.05.14, 14:23
02.03.14, 19:16
18.11.13, 14:48
22.03.13, 03:05
22.02.13, 15:45
Posts
10.01.17, 16:37
19.02.16, 06:03
19.02.16, 06:00
17.01.16, 11:00
12.01.16, 13:10
25.11.15, 08:19
Script of the Moment
Stroke Tone Line 10.03.09