on 08-12-2009 8:07 AM
Hi,
I want to generate 4-Digit Positive Random Number in the Mapping for a field. Could anyone please provide Inputs or a UDF.
Regards,
Varun
Hi,
Instead of UDF.. you can do this... Use the standard function current date which will return date and time.... pass this to the standard String function to substring and use it..
~SaNv...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This is the UDF I have Used
java.util.Random randomNumber;
String TransactionId = "" ;
randomNumber = new Random();
long longNumber = randomNumber.nextLong();
if (longNumber < 0)
{
longNumber = longNumber * (-1);
}
longNumber += 10000;
TransactionId = (String.valueOf(longNumber)).substring(0, 4);
return TransactionId ;
Thanks everyone for your Inputs
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
you can try this also
int x = (int)(Math.random() * 9999)+1000
random()
Returns a double value with a positive sign, greater than or equal to 0.0 and less than 1.0.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
use Random class from package java.util
Random:
Random is the class of java.util.*; package. This class is used to create a random number
nextInt():
This method returns a random number in random number generator's sequence. If you pass a value to the method then the method return the random number in the mentioned range otherwise it will generate the random number in sequence according to the random number generator.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
try
import java.util.Random;
Random generator = new Random();
int random_number = generator.nextInt(9999) + 1000;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Varun,
You can use Current time and date or combination of time,date and any numeric field from payload.Define some mathematical calculation in UDF and truncate it in the UDF it self to 4 digits using substring.Even while writing UDF you need to convert the values from string to Integers and perform calculations as UDF takeas inputs as String values.
Thanks,
Ram.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
87 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.