On Sun, Nov 04, 2007 at 12:52:18AM -0700, timROGERS wrote:
> 
> I am making a OpenSocial gadget that chooses a random friend of the
> OWNER's, and then displays there photo, there name and a link to there
> profile. Basically, I want to use this construct from the sample:
> 
> viewer_friends.each(function(person) {
>     var thumb =
> viewer.getField(opensocial.Person.Field.THUMBNAIL_URL);
>     var profile =
> viewer.getField(opensocial.Person.Field.PROFILE_URL);
>     profile = 'http://sandbox.orkut.com' + profile;
>     html += '<a href="' + profile + '" target="_top"
> style="float:left">';
>     html += '<img src="' + thumb + '"/>';
>     html += '</a>';
>   });
> 
> But instead of doing each member, I want to randomly select one. How
> would this be done?

This is really a basic javascript question, not an opensocial issue,
but here goes...

IIRC viewer_friends is an array, thus you can use javascript's
random() function multiplied with viewer_friends.length to find an
offset into the array.

-- 
Paul Lindner
hi5 Architect
[EMAIL PROTECTED]

Attachment: pgpv6jQdBU9XR.pgp
Description: PGP signature

Reply via email to