[Home]

Summary:ASTERISK-04696: [patch] app_rand
Reporter:powerkill (powerkill)Labels:
Date Opened:2005-07-26 16:23:15Date Closed:2011-06-07 14:03:03
Priority:MajorRegression?No
Status:Closed/CompleteComponents:Applications/General
Versions:Frequency of
Occurrence
Related
Issues:
Environment:Attachments:( 0) app_rand.c
( 1) app_rand2.c
Description:Hi,
I need to get a random number in my extension.conf for absolute timeout
So I decided to write a new app
It's easy one but it's doing what I need
Simple usage:
exten => s,1,Rand(timeout,7200,100)
exten => s,2,Noop(${timeout})
Set timeout with a random number between 7200 and 7300
I don't have access to my fax right now I will fax the disclaimer ASAP
Comments:By: Michael Jerris (mikej) 2005-07-26 16:52:48

please make this a function, not an app.

By: Tilghman Lesher (tilghman) 2005-07-26 18:32:20

- You need to protect the modulus operator from possibly being used with 0, or this will segfault Asterisk.
- You might consider using random() instead of rand(), since rand() has a rather notable bug (being that it produces a sequence of ODD-EVEN-ODD-EVEN ad infinitum).
- The format of this module is inconsistent with the CODING-GUIDELINES document.  Please indent all lines with tabs.  The brace style is also faulty.

You will need to change at least the first and third items, as well as recoding this into a function before it will be considered for CVS.

By: Tilghman Lesher (tilghman) 2005-07-26 18:33:02

Oh, and you definitely need a disclaimer on file.

By: powerkill (powerkill) 2005-07-27 02:37:22

Thanks for all your remarks I will correct them and send it back

By: Olle Johansson (oej) 2005-07-27 02:49:15

We already have an random() application btw, please rewrite the existing one!

By: Tilghman Lesher (tilghman) 2005-07-27 09:20:40

oej:  App Random() does something completely different.

powerkill:  Do not rewrite Random().

By: Olle Johansson (oej) 2005-07-27 10:20:32

Please explain to me the difference. We can't have both random and rand as functions, better to have one with different options... Or I must be missing something significant here.

By: Tilghman Lesher (tilghman) 2005-07-27 12:14:35

Rand or RAND, as it will be when it is a function, generates a pseudo random number in a specified range.  Random jumps to specified label, based upon a probability.  They are completely different beasts.

By: Tilghman Lesher (tilghman) 2005-07-27 12:15:51

Random is an app, and MUST BE an app, due to it's influence on the callpath.  RAND should be a function, since it does not affect callpath, but is simply a value generator.

By: Olle Johansson (oej) 2005-07-28 02:33:58

Ok, I see. Thanks for taking the time to explain it.

By: powerkill (powerkill) 2005-07-28 05:26:22

I use coding guide and indent program
Check if limit is not 0
Sorry it's the first time I submit a apps.

By: Michael Jerris (mikej) 2005-07-28 08:46:14

Thanks for the updates, but, 1) You didn't upload them, and 2) you need to convert this to a function (see the funcs dir in cvs-head).

By: powerkill (powerkill) 2005-07-28 10:29:26

OK I will learn how it's work and adapt it.

By: Tilghman Lesher (tilghman) 2005-08-15 13:44:53

Closed pending reimplementation as a dialplan function.  Reopen when ready.