By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,677 Members | 1,076 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,677 IT Pros & Developers. It's quick & easy.

Modify code from random to sequence

P: n/a
Hi, I am trying to modify some code in a toolbar I have for generating
random 'spam' entries on my forum.

I have managed to extract all the relevant files from the firefox .xpi
file and the .jar file, the code of interest initially looks like so
(this was written by someone else and I suspect it was partially taken
from another source prior to that too so I'm unsure if the following
code is all necessary);

function Tools_SpamSeries() {
var seed = _randomSeed();
var qoute = _getQoute();
for(var i=0; i<50; i++) {
_commentCount++;
//_postComment(qoute + " :" + seed + " #" + (i
+1));
_postComment(_commentCount);
}
//alert("Spamming Complete");

As you can tell it currently uses numbers up to 50 but I never
actually get 50 output 'comments', it seems to generate the numbers
then output them randomly and leave a few out.

Ideally I would prefer to have it start at '1' and work its way
sequentially up to '50' - 1,2,3,4,5...48,49,50 - END. (Total 50
comments)

But at present the numbers are all jumbled.

7,12,8,9,16...28,33,35 - END (Total 35 comments for example)

Eventually I would replace the numbers with comments perhaps but I
want to understand the workings of this first (looks quite
straightforward but not enough for me to figure out or find the syntax
required in place of the existing code).
Nov 15 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
G Love wrote:
Hi, I am trying to modify some code in a toolbar I have for generating
random 'spam' entries on my forum.
[...]
function Tools_SpamSeries() {
var seed = _randomSeed();
var qoute = _getQoute();
for(var i=0; i<50; i++) {
_commentCount++;
//_postComment(qoute + " :" + seed + " #" + (i
+1));
_postComment(_commentCount);
}
//alert("Spamming Complete");

As you can tell it currently uses numbers up to 50 but I never
actually get 50 output 'comments', it seems to generate the numbers
then output them randomly and leave a few out.
You do not seem to have initialized _commentCount to begin with, so the
result of _commentCount++ is unknown (may be NaN). The rest of the relevant
code you have either commented out or omitted, so there is no telling what
happens.

That said, if the first _postComment() call was not commented out, then
there might as well be the source of your problem as you use the value of
see, which might be a random number, in the argument. Then again, there is
no telling what _randomSeed() returns as that, too, is not a built-in.

BTW, shouldn't it be "quote" instead?
PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f8*******************@news.demon.co.uk>
Nov 15 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.