Recent Widgets


Register for DashboardWidgets

Recent Forums Posts

Partners


iCompositions

MacDesktops.net

RSS Showcase
RSS Comments
RSS Forums

This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies. Posted in: Widget Design

Random quotes aren't so random

Author Message
skyhawkrider



Joined: 06 Jul 2005
Posts: 20
Location: Boulder, CO

Posted: Thu Sep 15, 2005 - 5:32 pm    Post subject: Random quotes aren't so random Reply with quote

I've been having problems getting my Uncle Sam widget to randomly display the quotes; right now, it starts up with the same one each time. Of course, I'll give you credit, but I just need a solution. Here's what I'm using:

Code:


var Quote = new Array()

Quote[0] = "Quote 0 here";

function showQuote() {
   var Q = Quote.length;
   var whichQuote = Math.round(Math.random()*(Q-1));
   document.getElementById('generator').innerHTML = Quote[whichQuote];
   return;
}



Thanks.
View user's profile Send private message Send e-mail Visit poster's website AIM Address Widgets
jtbandes



Joined: 17 Jun 2005
Posts: 269
Location: Oregon

Posted: Thu Sep 15, 2005 - 7:46 pm    Post subject: Reply with quote

This sound suspiciously like the "Random passwords aren't so random" news article...
View user's profile Send private message Send e-mail Widgets
jonlink



Joined: 27 May 2005
Posts: 172

Posted: Thu Sep 15, 2005 - 8:36 pm    Post subject: Reply with quote

good lord, not only has been been covered, but i also left a comment in your widget posting about it. this has also been well documented in tons of places like the front page of this website http://www.dashboardwidgets.com/news/comments.php?id=42_0_2_0_C. math.random will return the same numbers on every start up of the widget. you need to come up with another method of getting a semi-random number.

it seems like you haven't even looked for an answer on this site before asking. what's worse is that would also mean you are looking to just have an answer handed to you. do some homework yourself first and if you get stuck people here will be happy to help.

if you are looking for a place to start feel free to look at & adapt what i've used in the simpsonbot widget. or take a look at any other widget that claims to have something randomly generated. or look on the web for javascript random number generators.

good luck
View user's profile Send private message Send e-mail Widgets
ceaser



Joined: 20 Sep 2005
Posts: 12
Location: Baltimore, MD

Posted: Wed Sep 21, 2005 - 8:43 am    Post subject: Here is an attempt Reply with quote

Since it's a quote generater and processing time is not important, you could develop a system where you grab the seconds from the clock (s=1-59) and grab the s'th random number. I would also use a system where you burn your numbers once you use them. Something like you keep an array of the last 10 random numbers you used, you keep looking for new ones untill you get one not on your list. When you get a new one, shift(), add new to end.

As for getting the same numbers everytime you start, is this evertime you load your widget (which gives me different numbers) or everytime you start Dashboard?
View user's profile Send private message Visit poster's website ICQ NumberWidgets
jonlink



Joined: 27 May 2005
Posts: 172

Posted: Wed Sep 21, 2005 - 10:33 am    Post subject: Reply with quote

if you want to know how to easily generate random numbers read this from macosxhints.com
View user's profile Send private message Send e-mail Widgets
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.

 
Powered by phpBB © 2001, 2002 phpBB Group