Jump to content

Random Letter Rule Always Returns Same Letter


jleger

Recommended Posts

I have a JavaScript function which returns a random letter, but when calling this from multiple text frames, all frames have the same letter. Refreshing the preview generates a new letter, but again, all frames have the same letter. It's as if the function is only called once even though it should be called by each text frame (in my opinion). Thanks!

 

----------------------------------------------

 
randomletters='ABCDEFGHIJKLMNOPQRSTUVWXYZ';
rindex = Math.floor(Math.random() * randomletters.length);
strReturn = randomletters.charAt(rindex);
return strReturn;

----------------------------------------------

 

Thanks!

-Joe

Link to comment
Share on other sites

Hi Joe,

 

You assumption is correct - text rules are executed only once per record. So in your job, the rule is executed once and then that the value is returned multiple times in your layout.

 

One way to achieve what you are after is to have separate rules - 1 for each placement of a different random letter in your template.

 

You could duplicate the rule you have now, but a cleaner way to do this is to make new rules that simply refer to the base rule you have here. These rules would be:

 

return Rule("RandomLetterRule");

Using this method, you are asking FusionPro to execute this base rule multiple times in a given template.

 

Now if you want to ensure that the same letter is never returned more than once in a given record, there's a couple options for that. I prefer a method where you do a random sort with a loop on your array in an OnRecordStart rule (so you pick 2 random position in the array and swap the values - repeat this a thousand times and you have a randomized array).

 

With the randomly sorted array then, you can have rules that return different positions in that array (so rule 1 returns array element 1, rule 2 returns array element 2, etc).

 

If you'd like some more info on this, please let me know.

 

hth

Link to comment
Share on other sites

  • 1 year later...

Hi Mark, I would like some more information on this. I have a job with a 110 names on Business Cards. There are five different versions of business cards. Each person is to get 50 of each of the different versions. They would like to have the versions alternate when we print them. Is this kind of thing possible?

 

Thanks,

Richard.

Link to comment
Share on other sites

I don't think this is the correct thread to post your question in. ;)

 

For your situation, I would create a 5-page template, with each page containing one version of your static business card art. I would then place a copy of the necessary variable frames on each page and create an OnRecordStart rule which includes the line:

FusionPro.Composition.repeatRecordCount = 50;

This should produce record 1 with all 5 cards, and then reproduce record 1 forty-nine more times so that you have a total of 250 cards, in alternating order of the 5 base art versions. The next 109 records would follow suit.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...