IMPORTANT ANNOUNCEMENT

These forums were permanently set to read-only mode on July 20, 2022. From that day onwards, no new posting or comment is allowed on the site, but the historical content remains intact and searchable.

A new location for posting questions about PlanetPress Suite is now available:

OL Learn - PlanetPress Classic (opens in new tab)

Topic Options
#24494 - 07/31/07 05:56 AM [Macro] Random numbers
Anonymous
Unregistered


How to install:

  • Copy the text in the code-window below to an empty notepad document.
  • Save the file to your PrintShop Mail installed directory, "Macro" folder, with the extension .js
  • Start (or restart) PrintShop Mail.

How to use:
  • Create a variable.
  • Use the expression builder to attach the RANDOMNUM(number) function to the variable. A number between 0 and the entered number will be returned.
  • Combine with INT(number) function to get integer numbers:
    INT(RANDOMNUM(number))

Limitations:

THIS INFORMATION IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. USE AT YOUR OWN RISK.
MACROS are NOT SUPPORTED in ANY way.


code:
// ****************************************************************************************************
//
// Random Number Generator Macro module for PrintShop Mail
//
// Language : JScript
// Author : Floris Dansen - Objectif Lune BV
//
// *** This macro is provided as is, it will not be supported, and no rights can be claimed ***
// *** Use at your own risk ***
//
// ****************************************************************************************************

// CALLBACK FOR FUNCTION DESCRIPTORS
// ====================================================================================================
function psmGetFunctionDescriptor(index)
{
if (index == 0)
return "NUMBER NUMBER+VOLATILE RANDOMNUM(NUMBER{number;Maximum of returned number.})\tGenerates a random number with the specified maximum.\t

RANDOMNUM(500) => 348";

return "";
};


// ****************************************************************************************************
// ****************************************************************************************************
//
// EXPRESSION FUNCTIONS IMPLEMENTATIONS
//
// Same name as 'KEYWORD' given in the descriptor, prefixed with 'psm'
// the 'psm' prefix is to prevent possible clash with the module's language keywords.
//
// ****************************************************************************************************
// ****************************************************************************************************
function psmRANDOMNUM(innum)
{
return Math.random() * innum;
}

// ****************************************************************************************************
//
// The functions below are sample implementations for the optional functions.
// (Note that this sample uses all optional functions to demonstratie there purpose and usage)
//
// ****************************************************************************************************

// CALLBACK FOR WARNING RETRIEVAL
// ====================================================================================================
var Warning="";
function psmGetWarning()
{
// This function is optional, only required if one or more functions need to issue warnings
// It is called each time after a plugin expression from this module is called.
// If no warnings should be given, an empty string should be returned.
var result = Warning;
Warning = "";
return result;
}

// CALLBACK FOR WARNING CAUSE PARAMETER NO.
// ====================================================================================================
var causeParameterNo = -1;
function psmGetWarningCauseParameter()
{
var result = causeParameterNo;
causeParameterNo = -1;
return result;
}

// CALLBACK FOR SETTING LANGUAGE
// ====================================================================================================
var LanguageSet = "";
function psmSetLanguage(lan)
{
LanguageSet = lan;
}





Edited by fleurys (09/01/10 01:44 PM)

Top
#24495 - 08/03/07 07:16 AM Re: [Macro] Random numbers
Anonymous
Unregistered


The script was updated today, because in certain situations, the number would remain the same throughout the job.

Now, each time the RANDOMNUM function is called, a new number will be retrieved.

Top