Random unique Integer
Hi Experts,
I need to generate a random unique 20 digit integer. I have tried all the QF05 series, but none of them satisfy my requirement (Integer 20 digit). Please suggest.
Thanks in advance
Ajith
Hi,
Check class:
CL_ABAP_RANDOM or
CL_ABAP_RANDOM_INT or
Check CL_ABAP_*
Thanks & Regards,
Navneeth K.
Similar Messages
-
How to specify a unique integer for each local variable defined in TestStand?
I have a .net application that reads all TestStand local variables, but for the .net application each local variable should have a unique integer number. Iterating through the locals and storing the index is not a good solution, because if a local variable is moved or deleted, the index will change.
Does anyone know how to do this in TestStand or having an idea how to this in my .net application?
Thanks.Thanks Doug for your reply. Using a GUID is not an option because this ID is too long. I will try to explain why I need this ID for. I have a lot of C# code that generates code to deal with a lot of instruments. For example to configure a device, user defined variables can be used to specify some settings or to store results. These variables are not stored in the generated code with a name but with an integer number. Now I want to try to be use all our existing device driver code with the TestStand sequencer. So, I need a translation between the name of a TestStand local variable and an integer number. After constructing the interface to my code I want to read all the variables from TestStand and now I need the integer ID to do the mapping to my variables. I know that I can use use your proposition 2 by encoding the unique ID into the name of the variable and parse the name of the variable to get it back, but this is not an automated way. This will be rather difficult if there are several hundreds of variables. For this reason I am looking for an alternative way. Looking forward for your response. Best regards
-
Hi,
I want to log TestStand data into an existing SQL database.
The step ID in my database is an integer (Integer data van -2^31 (-2.147.483.648) tot 2^31-1 (2.147.483.647)),
so a GUID id does not fit in this field.
Is it possible to change the GUID id to a unique integer number on sequence level? TestStand should stuff the integer id automatically while inserting steps…
If a number field is added to the test steps definitions, is it possible that TestStand automatically fills the numeric step ID for each instance of the test steps in the sequence while inserting the step?
Best regardsYou could use the index and step group of the step to create a numeric id, but it will change as soon as any step is inserted before the step.
If you absolutely can't change your database and have to make it work, you could always generate/update a map of GUID to integer id for each sequence, perhaps at runtime from the first step in the sequence. Basically, have the first step create or update the mapping. You'd also likely need to store a last used id so you know what id to start with when you add anything to the map.
Really probably the best solution is to change the database though. If you really want a unique ID per step that survives inserting new steps before it, then a GUID is a much simpler way to go.
Hope this helps,
-Doug -
I want to generate eight digit Random Unique Numbers as Identification numbers in my application. example: 12354553,23455663,45645123... so on.
Does oracle provide any procedure or function using which i can generate these numbers.I would go for dbms_random+sequence
SQL> create sequence s maxvalue 9999 cycle minvalue 0;
Sequence created.
SQL> select trunc(dbms_random.value(0,100000000),-4)+s.nextval from dual;
TRUNC(DBMS_RANDOM.VALUE(0,100000000),-4)+S.NEXTVAL
47850000
SQL> select trunc(dbms_random.value(0,100000000),-4)+s.nextval from dual
TRUNC(DBMS_RANDOM.VALUE(0,100000000),-4)+S.NEXTVAL
66250001well, you could try to obfuscate this unique number if you want -
Unique random alpha num string
Hi Guys,
I have a unique question.
I need to generate a unique random Alpha Num string.
I cannot use 0,5,8 and 0,S,B in the generated output string.
The string generated should be no more than length 7 max
Pls help.Following solution generates random unique strings combinations
from any given base set. Here is a sample output.
$ java UniqueStringGenerator 7 100 10
FCT2RYT
2M31BU8
VV8FU4Z
BON2MKE
OKUJZT0
68E8X8S
YTNLZAY
CPEKPFP
C176M24
GQB9QE9The idea is quite simple.
Pre-work:
1. The base set is first mixed to increase entropy.
2. All possible combinations are divide up into random buckets.
Work for every unique string:
1. Pick a bucket at random.
2. Get next number in bucket.
3. Convert the number to a unique string token.
It is possible to adjust how much entropy you want in your
sequence of generated combinations by choosing how many buckets
the generator contains. However, every bucket will take up some
memory.
import java.util.*;
import java.math.*;
public class UniqueStringGenerator {
public static String[] ALPHA_NUM =
{"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P",
"Q","R","S","T","U","V","X","Y","Z",
"0","1","2","3","4","5","6","7","8","9"};
private List _parts = null;
private List _buckets = null;
private int _length;
private BigInteger _range = null;
public UniqueStringGenerator(String[] parts, int length,
int numberOfBuckets) {
_length = length;
// mixing the base set to increase entropy
_parts = new Vector();
List all = new Vector();
for (int i = 0;i < parts.length;i++) {
all.add(parts);
while (all.size()>0) {
int p = (int)(((double)all.size())*Math.random());
_parts.add(all.get(p));
all.remove(p);
// dividing all possible numbers into given number of buckets
BigInteger numParts = BigInteger.valueOf(parts.length);
_range = BigInteger.ONE;
for (int i = 0;i<_length;i++) {
range = range.multiply(numParts);
TreeSet starts = new TreeSet();
Random rand = new Random();
while (starts.size()<numberOfBuckets-1) {
BigInteger bi = new BigInteger(_range.bitLength(), rand);
if (bi.compareTo(_range)<=0) {
starts.add(bi);
_buckets = new Vector();
Bucket last = new Bucket(BigInteger.ZERO);
_buckets.add(last);
for (Iterator i = starts.iterator();i.hasNext();) {
Bucket next = new Bucket((BigInteger)i.next());
_buckets.add(next);
last.setTo(next.getStart());
last = next;
last.setTo(_range);
private class Bucket {
private BigInteger _start;
private BigInteger _next;
private BigInteger _to;
public Bucket(BigInteger start) {
_start = start;
_next = start;
public void setTo(BigInteger to) {
_to = to;
public BigInteger getStart() {
return _start;
public boolean hasNext() {
return next.compareTo(to)<0;
public BigInteger next() {
BigInteger ret = _next;
next = next.add(BigInteger.ONE);
return ret;
public String toString() {
return "["+start+", "+next+", "+_to+"]:"+hasNext();
public String nextUnique() {
// getting next big integer
BigInteger left = null;
while (left==null) {
Bucket b = (Bucket)
buckets.get((int)(Math.random()*buckets.size()));
if (b.hasNext()) {
left = b.next();
// converting it to a combination
StringBuffer unique = new StringBuffer();
BigInteger base = BigInteger.valueOf(_parts.size());
for (int i = 0;i<_length;i++) {
BigInteger[] resRem = left.divideAndRemainder(base);
left = resRem[0];
unique.append(_parts.get(resRem[1].intValue()));
return unique.toString();
public static void main(String[] args) {
if (args.length!=3) {
System.out.println("Usage: UniqueStringGenerator "+
"[string size] [# buckets] [# prints]");
return;
int length = Integer.parseInt(args[0]);
int numBuckets = Integer.parseInt(args[1]);
int num = Integer.parseInt(args[2]);
UniqueStringGenerator usg = new UniqueStringGenerator
(UniqueStringGenerator.ALPHA_NUM, length, numBuckets);
for (int i=0;i<num;i++) {
System.out.println(usg.nextUnique()); -
OK, firstly, I am a Java n00b. I am not creating a program, just editing some source, but I need some help. What I need, are 5 different variables, each with a random value (integer) between 1 and 5 (inclusive), but, I don't want to variables to have the same value. The outcomes I'm looking for could be as follows:
t = 4
i = 3
g1 = 5
g2 = 1
y = 2
and then the next time the code is run I might get:
t = 1
i = 5
g1 = 4
g2 = 2
y = 3
Each variable has a random value (integer) between 1 and 5 (inclusive), but no 2 variables have the same value.
Here is what I tried:
Random rand = new Random();
int t = (rand.nextInt(5) + 1);
int i = (rand.nextInt(5) + 1);
int g1 = (rand.nextInt(5) + 1);
int g2 = (rand.nextInt(5) + 1);
int y = (rand.nextInt(5) + 1);
// While i is the same as t, make i a new random integer between 1 and 5. Yes? Or no...?
do {
i = (rand.nextInt(5) +1);
} while (i == t);
do {
g1 = (rand.nextInt(5) +1);
} while (g1 == t);
do {
g1 = (rand.nextInt(5) +1);
} while (g1 == i);
do {
g2 = (rand.nextInt(5) +1);
} while (g2 == t);
do {
g2 = (rand.nextInt(5) +1);
} while (g2 == i);
do {
g2 = (rand.nextInt(5) +1);
} while (g2 == g1);
do {
y = (rand.nextInt(5) +1);
} while (y == t);
do {
y = (rand.nextInt(5) +1);
} while (y == i);
do {
y = (rand.nextInt(5) +1);
} while (y == g1);
do {
y = (rand.nextInt(5) +1);
} while (y == g2);But when I use the variables in the next part of the program, sometimes it works, but sometimes 2 of them are the same. Sometimes even 4...
Can someone help me please?Thinking about it now though, I would like to learnproperly. What is a good Java guide that starts from
scratch?
I think the Core Java books, by Cay Horstmann, are a
great way to start learning Java. I refered to his
books constantly durning college:
http://www.amazon.com/exec/obidos/tg/detail/-/013148202
/qid=1096410169/sr=1-1/ref=sr_1_1/104-3324308-3016709?v
glance&s=books
Sun's basic Java tutorial
Sun's New To Java Center. Includes an overview of what Java is, instructions for setting up Java, an intro to programming (that includes links to the above tutorial or to parts of it), quizzes, a list of resources, and info on certification and courses.
http://javaalmanac.com. A couple dozen code examples that supplement The Java Developers Almanac.
jGuru. A general Java resource site. Includes FAQs, forums, courses, more.
JavaRanch. To quote the tagline on their homepage: "a friendly place for Java greenhorns." FAQs, forums (moderated, I believe), sample code, all kinds of goodies for newbies. From what I've heard, they live up to the "friendly" claim.
Bruce Eckel's Thinking in Java (Available online.)
Joshua Bloch's Effective Java
Bert Bates and Kathy Sierra's Head First Java. -
HOW DO I KEEP AN ARRAYLIST IN RANDOM ORDER AFTER EXITING THE SUB ROUTINE CONTAINING IT
PLEASE HELP!I am trying to go from VB4 which I loved to VB2010 which I find somewhat more challenging. I’ve searched the web for help and have adapted the following to my project. This code does
rotate randomly through every card in the deck and displays unique cards until all have been drawn. BUT I want to draw one card
only from the first “hat” of Boy’s names; then draw the second card from the second “hat” of Girl’s names and repeat this process until all cards in both decks have been drawn. How do I get the TextBox (OR any
MsgBox) to display JUST ONE unique random card at a time so I can exit that deck and go to the next deck?
On my form, I have two TextBoxes (to display the names (as drawn), two buttons (to re-load each deck once exhausted) and one command (&End)control (to end the process). I created two ArraysLists
(to hold the Boys names and Girls names separately) and two ArrayLists to hold the cards for the random decks when created in code.
I can
NOT get this code to draw random UNIQUE names once I exit the deck. I have tried to ReDim the deck; randomly pull a card from the second (temp) deck, etc
NOTHING seems to work.
WHY does my deck lose randomness once I exit it?
How can I fix it? I don’t understand this. Below is the code for the "hat" with the 10 girl's names.
Also, when I don't loop through all the cards, I usually get "An Out of Index exception was not handled" error. Hope someone can help me with this problem. It seems like this should
be easy BUT I'm baffled. Thank you for any help.
Imports System.Collections.Generic
Public Class Form1
Dim Count As Integer
Dim Rcard As New ArrayList
Dim Dcard As New ArrayList
Dim NewRDeck As New ArrayList
Dim NewDDeck As New ArrayList
Dim temp_Rnum As Integer
Dim temp_Dnum As Integer
Dim MyRand As New Random()
Public Sub Rcards_Click(sender As Object, e As System.EventArgs) Handles Rcards.Click
While Rcard.Count > 0
Dim temp_Rnum As Integer = Int(MyRand.Next(Rcard.Count))
NewRDeck(temp_Rnum) = Rcard(temp_Rnum)
Rem Check that the ArrayLists work correctly and display properly
MsgBox(Rcard(temp_Rnum), , "New random card selected is: ")
Console.WriteLine(Rcard(temp_Rnum))
Rcard.Text = (Rcard(temp_Rnum))
REM Now remove the Rcard with the random number generated so it can't be drawn again
Rcard.RemoveAt(temp_Rnum)
End While
REM When all 10 cards have been picked, alert player to re-load deck if desired.
MsgBox("No new cards left in deck; please Re-Load the cards. Thank you.")
EndSub
End ClassHi Acamar,
Thank you for such a fast response. Sorry if my text wasn't clear. I'm really struggling with creating unique random elements in Collections in VB2010 and feel I understand ArrayLists better than some of the other Collection types.The code works perfectly
and generates unique random cards until the original deck is exhausted. Then it prompts the user to re-load the original deck so it can be reused if needed. But I need to draw one card only and exit the deck. Then when I click on the TextBox again, I want
that deck to be in the same random order - just minus any cards I have already drawn and thrown away. Thanks again for your help.
Here's the rest of the code for just the girl's "hats" of names, if it helps:
Private Sub btnShuffleRCards_Click(sender
As System.Object, e
As System.EventArgs)
Handles btnShuffleRCards.Click
Dim j As
Integer
For j = 1 To 10
NewRDeck.Add(j)
Next j
Randomize()
REM Create original Deck with names for the girls.
Rcard.Add("1 HELEN”)
Rcard.Add("2 OLIVIA")
Rcard.Add("3 <st1:city w:st="on"><st1:place w:st="on">ALICE</st1:place></st1:city>")
Rcard.Add("4 VALERIE")
Rcard.Add("5 DONNA")
Rcard.Add("6 ZELDA")
Rcard.Add("7 MARGARIE")
Rcard.Add("8 <st1:city w:st="on"><st1:place w:st="on">NANCY</st1:place></st1:city>")
Rcard.Add("9 WANDA")
Rcard.Add("10 IRENE")
End Sub -
Using Weblogic jms message id for unique id
Hi All,
We have a requirement to generate random unique id for each message processed by the application. We are planning to leverage weblogic jms message id for this purpose rather than building our own application logic for this purpose . Will there be any issue adopting this ? We think weblogic jms message id will be unique across the cluster as id is a hash of current timestamp + jms server name + wl server name + ?? .. is this correct ?
TIA
AtheekHi Atheek,
It depends on what are you planning to do with that id, as there are some gotchas on Weblogic's JMSMessageID generation.
I guess the msg id could be considered statiscaly unique as Tom says, but the msg id will change during the livecycle of your message, surprise! (yea, the JMS spec allows the JMS server to modify the msg ids).
So if you want to use that id to correlate messages id, or to group info related to one message, using JMSMessageID could be a problem.
You can consider to generate a UUID, using Java 1.5 support (java.util.UUID) or a external library (JUG http://jug.safehaus.org for instance), and attach that id as a JMSCorrelationId or a user defined property.
Hope this helps -
Random Number in the Transformation File
Hi All,
I need to send a random number while mapping from one xsd to other in the xsl file . The random number should be alpha numeric with 5 chartacters. I tried using generate-guid() but it generates 32 characters. How do u i shrink this to 5 characters and still get a random value?
Thanks
MJJust to add,
the above mentioned function does not generate integers. For that u need to truncate the output of random to integer as below
SELECT TRUNC(dbms_random.value(10000, 99999)) FROM dual;
Edited by: Marius J on Sep 15, 2009 1:33 AM -
How to make the random number not repeat ?
public class randomla {
public static void main(String[] args) {
double a = 0.0;
for(double i=0 ; i<5 ; i++){
a = Math.random();
System.out.println((int)(a*6));
}Are you saying that you want to print 5 random unique numbers - 12, 5, 459, 2, 42 as opposed to 12, 5, 459, 12, 42?
If so you have two options:
1. Place the generated number in array or collection only if it is not already present and then when you have 5 numbers print them out (or you could print them out when generated).
2. Place all possible numbers into a collection, shuffle them and then print out the first five numbers. -
Stop random numbers repeating HELP!!
i have been trying to create ten random numbers between 0-99 without them repeating and put them into an object array. this is the code i have been trying but it doesn't seem to work.
public static void main (String[] args)
Random generator = new Random();
Object[] data = new Object[10];
int marker = 0;
for (int i = 0; i< data.length; i++)
int number = Math.abs( generator.nextInt() )%99+1;
Integer random = new Integer ( number );
for ( int a = 0; a < data.length; a++ )
if ( ( data[a] ) == random )
marker = marker + 1;
if ( marker == 0 )
data[i] = random;
else
i = i - 1;
marker = 0;
for (int i = 0; i < data.length; i++)
System.out.println( data[i] );redesign your code, how is that look? :)
public static void main (String[] args)
Random generator = new Random();
Object[] data = new Object[10];
Set set = HashSet();
while(set.size() < 10)
int number = Math.abs( generator.nextInt() )%99+1;
Integer random = new Integer ( number );
set.add(random);
Iterator iter = set.iterator();
int j = 0;
while (iter.hasNext())
data[j++] = iter.next();
for (int i = 0; i < data.length; i++)
System.out.println( data[i] );
}--lichu -
Creating random BigIntegers, 0 - X
Hey guys Im trying to create a random BigInteger between 0 and X where X is a random but predetermined BigInteger number.
I know I can create a random big integer using:
BigInteger(int numBits, Random rnd) .
But its not guaranteed to be less than 'X':
e.g an 8bit BigInteger can be anything between 0 - 256 but my 8 bit X value could be 112.
Is there a simple method for doing this? I could do it using doubles fairly easily but I don't know how
to convert a double back into a BigInteger...
Any ideas would be appreciated...
Thanks,
ShanonWhat about this:
public BigInteger nextBigInteger(BigInteger n){
BigInteger result;
Random random= new Random();
do{
result= new BigInteger(n.bitLength(), random);
} while(n.compareTo(result) <= 0);
return result;
It gives uniform results, and do-while loop will
be executed 1 - 2 times (on average) so it doesn't seem like a problem. -
How to use sequence in BPEL transformation
Hi All,
I want to use some kind of random unique number in my xsl mapping. I Thought to use a sequence which I generated in database, but in xsl mapping I didn't get a way to use database functions. Can anyone suggest something.
Thanks in Advance.Hi Roshni,
You seems to use an external parameter inside the XSLT. you can you it as <param> defined in xslt. and call that external parameter with the same name inside the xslt to use.
suppose you need a count variable inside xslt which comes from external service as DB using Adapter to fetch the value. Now inside xslt:
and then define
+<xsl:param name="Count"/>+
and assign value to your
+<xsl:variable name="CountDetails" select="integer($Count)"/>+
before xslt call the variable which needs to be populated and assign it to param defined in xslt
i.e.
+<assign name="Assign_XSLParams">
<copy>
<from expression="'Count'"/>
<to variable="SMS_int"
query="/ns3:parameters/ns3:item/ns3:name"/>
</copy>
</assign>+
Hope this helps !!
Reg,
MS -
Java Array Out Of Bounds Problem
In order to conduct an experiment in java array sorting algorithm efficiency, i am attempting to create and populate an empty array of 1000 elements with random, unique integers for sorting. I've been able to generate and populate an array with random integers but the problem is - for whatever size array I create, it only allows the range of numbers to populate it to be the size of the array, for instance, an array of size 3000 allows only the integer range of 0-3000 to populate it with or I get an out of bounds exception during runtime. How can you specify an integer range of say 0-5000 for an array of size < 5000? Any help is appreciated.
Another approach is to fill the array with an
arithmetic sequence, maybe plus some random noise:
array[i] = i * k + rand(k);or some such, so they are unique,
and then permute the array (put the elements
s in random order)
for (i : array.length) {
transpose(array, array[rand(i..length)]); }
Along those lines, java.util.Collections.shuffle can be used to randomly shuffle a List (such as an ArrayList). Create an ArrayList with numbers in whatever range is needed. Then call java.util.Collections.shuffle(myArrayList). [It is static in Collections--you don't need to [and can't] create a Collections object.] -
General project information
Using Captivate 5.5 to create quizzes.
Publishing to SCORM 1.2
Report Data: Quiz results and Slide Views
Reporting Level: Interactions and Score
I have changed the Interaction ID to text corresponding with the question rather that a seemingly random number.
The issue – When trying to view the details in our LMS the following error appears.
ERROR
clsOLEDB:openRecordset() : Conversion failed when converting the varchar value 'TCBYOTheft' to data type int.
ADODB.Recordset error '800a0e78'
Operation is not allowed when the object is closed.
/reports/reportViewer.asp, line 1724
Note: I beleive "TCBYOTheft" is the interaction ID of the first (randomized) question slide.
Any help would be appreciated.The Interaction ID doesn't necessarily have to be an integer. It just needs to be unique across the entire course. I've never seen an LMS that demanded an integer for this ID. I think your error might be due to the LMS encountering two interactions with the same ID.
Captivate will track and ensure that the Interaction IDs are unique for all scored interactions in a given project file. But it obviously can't know about the interactions that might exist in another project file that you might happen to bundle up with this one as part of a multi-SCORM packaged course. A randomly-generated integer is a good start, but for even greater insurance of uniqueness across larger multi-module courses, you need to go further.
The problem is that many authors use Captivate templates as a way to initialise course modules and if (like me) you have the quiz questions already set up ready to go in these templates so that you save formatting time, then the Interaction IDs are already allocated in the template, and will be inherited by the projects spawned from these templates. This can mean that more than one module in the course could potentially have an interaction with the same ID.
To get around this, Captivate provides a Quiz Setting for an Interaction ID Prefix so that you can tag all interactions in a project file as belonging to the same module.
So, if you KNOW that your project file will be part of a larger multi-module course, you can make sure each module's interactions are still unique by appending the prefix.
It's always a good idea once you've created your modules to go to Project > Advanced Interaction dialog and just make sure that all scored Interactions have the prefix.
Maybe you are looking for
-
Contacts wont sync from iphone to imac
iPhone 4/os5 , imac/OS10.6.8, itunes10.5.1 I am not using mobile me, but prefer to sync manually over the hard wire. Calendars, music and mail are fine. (Mail is over 3G) Data and contacts added on phone do not appear on iMac/main computer. This has
-
Hi All, Plz let me know where can we get the ABAP delta documents, as i have to prepare the list of all ABAP (Eg: keywords) changes made to SAP from 3.1H to ECC 6.0. Thanks.
-
Adobe acrobat RDS Requirements
Dear All, We have a slow printing issues with Adobe Acrobat on a RDS Windows 2012R2 Infrastructure. Can anyone tell me if Adobe Acrobat Standard XI is supported by Acrobat on Windows 2012R2 RDS. I cannot find any specific requirements required for Wi
-
How to set my Mac to wake automatically when invited to join a video chat?
Is it possible to set my Mac to wake automatically from Sleep when invited to join a video chat? Also, is it possible to show that I am still available when my Mac is sleeping? It seems that if these settings are not possible, there can be no spontan
-
Experiencing very small text using adobe connect on my new Microsoft Surface 3. Any solutions?