RANDOM SEQUENCE

HI,
CAN I GET A RANDOM NUMBER USING A FUNCTION OR CALLING A SELECT...'SOMETHING' ... FROM DUAL ???
THANKS, MARCO.

Here is an example from site http//asktom.oracle.com
Randomly generate and unique is sort of an oxymoron.
What I've done in the past is to combine 3 or so numbers together to achieve this. One that I use alot is:
sequence_name.nextval | | to_char( sysdate, 'DDDSSSSS' )
You can do the same thing with a random number (replace the to_char(sysdate) with a random number of a FIXED length -- eg:
sequence_name.nextval | | to_char( random.rand,'fm00000' )
See
http://osi.oracle.com/~tkyte/Misc/Random.html
for howto generate a random number.
You need to combine a sequence or some other UNIQUE thing with the random number to get uniqueness.
Another option is to use the sys_guid() function available in 8i. For example:
ops$[email protected]> create table t as select sys_guid() u_id from dual;
Table created.
ops$[email protected]> desc t;
Name Null? Type
U_ID RAW(16)
ops$[email protected]> select * from t;
U_ID
722EF40A77F1386AE034080020A767E0
sys_guid() generates a 16byte globally unique key that is non-sequential.
If you need it as a number, it can be converted:
ops$[email protected]> set numformat
999999999999999999999999999999999999999999999999
ops$[email protected]> select to_number(
'722EF40A77F1386AE034080020A767E0',
'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' ) from dual;
ops$[email protected]> /
TO_NUMBER('722EF40A77F1386AE034080020A767E0','XXXXXXXXXXXXXX
151775786912318261447473874650479945696
ops$[email protected]> select sys_guid(),
2 to_number(sys_guid(),'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' )
from dual;
SYS_GUID()
TO_NUMBER(SYS_GUID(),'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
722EF40A77F2386AE034080020A767E0
151775786912320679299113103908829358048
ops$[email protected]> /
SYS_GUID()
TO_NUMBER(SYS_GUID(),'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
722EF40A77F4386AE034080020A767E0
151775786912323097150752333167178770400
Helena

Similar Messages

  • Random sequences

    How would i go about creating random sequences of with user supplied number and length, i am stuck as far as i can get is this:
    /** creates random sequences */
    public void randomSequence(int number, int length)
        for(int i = 0; i < number; i++)// number of sequences to be made
            for(int j = 0; i < length; j++){ // length of those sequences
                if(numSeq >= seqArray.length){
                    seqArray = doubleArray();
                seqArray[i] //here is where i get stuck!!!????
       }

    My personal crusade against really bad "random"
    numbers...Even your numbers are still not great ..., and there
    is no reason at all to use "SecureRandom" if you don't
    really care about the randomness you get. (i.e. it's
    not for any statistical, cryptographical purpose ...)
    And if you want "really" random numbers, have a look
    at
    http://www.random.org
    http://www.fourmilab.com/hotbits/
    and http://www.randomnumbers.info/
    and if you feel like it
    http://superhappycool.blogspot.com/2004/10/article-real
    y-random-numbers.html
    :)I know about (and use) a few of those, and others. It's not that util.Random is horrendous, it's just worse than should be acceptable ( http://www.alife.co.uk/nonrandom/ ). Also, you'll note that I said "at the very least use... [SecureRandom]."
    ~Cheers

  • Generating a Random sequence

    Hello All,
    I want some help writing a method which generates a set of 100 numbers with values 0 and 1, but the input should be percent of number of 1's and 0's...I mean if I give 20% for 0's and 80% for 1's then in the generated sequence I should get 20, 0's and 80, 1's...randomly.....hope Iam clear with my question.....please help me
    Thanks,
    Raghu.

    Here is a utility you can use.. you just need to make the call to get the proper random number of ones and pass the size you want.. it returns an array of strings of ones and zero's but you can convert it to whatever type you need.
    --John Putnam
    import java.util.*;
    * <p>Title: ShuffleBits</p>
    * <p>Description: example of creating a string of 1's and 0's and shuffling them</p>
    * <p>Copyright: Copyright (c) 2003</p>
    * @author John Putnam
    * May be use freely with inclusion of this copyright notice
    * @version 1
    public class ShuffleBits
          * method to create an array of strings of 1's and zeros then shuffle them
          * @param numberOfOnes exatly to include (the rest are zero's)
          * @param maxNumberOfBits total number of ones and zeros.
          * @return randomized list of ones and zeros
      public String[]  randBits(int numberOfOnes, int maxNumberOfBits)
           ArrayList bits  = new ArrayList(maxNumberOfBits);
           for(int i=0;i<numberOfOnes;i++) bits.add("1");
           for(int j=0;j<(maxNumberOfBits-numberOfOnes);j++) bits.add("0");
           Collections.shuffle(bits);  //--do the shuffling of order
           Iterator ib = bits.iterator();
           String[] bitsBack = new String[maxNumberOfBits];
              //--pull out the shuffled bits
           int rb = 0;
           while(ib.hasNext()) bitsBack[rb++] = (String)ib.next();
           return bitsBack;
       } //--end randBits
    //--------------------------------unit testing main--------------------------------
       public static void main(String[] args)
             ShuffleBits test = new ShuffleBits();
             int numOnes;
             int maxNumber;
             String[] bitsBack = null;
             numOnes = 5;
             maxNumber = 15;
             bitsBack = test.randBits(numOnes,maxNumber);
             System.out.println("\n--Test for #ones: " + numOnes + " max: " + maxNumber);
             for(int i=0;i<maxNumber;i++) System.out.println("--I: " + i + " bit: " + bitsBack);
    numOnes = 12;
    maxNumber = 15;
    bitsBack = test.randBits(numOnes,maxNumber);
    System.out.println("\n--Test for #ones: " + numOnes + " max: " + maxNumber);
    for(int i=0;i<maxNumber;i++) System.out.println("--I: " + i + " bit: " + bitsBack[i]);
    numOnes = 12;
    maxNumber = 15;
    bitsBack = test.randBits(numOnes,maxNumber);
    System.out.println("\n--Test for #ones: " + numOnes + " max: " + maxNumber);
    for(int i=0;i<maxNumber;i++) System.out.println("--I: " + i + " bit: " + bitsBack[i]);
    numOnes = 12;
    maxNumber = 15;
    bitsBack = test.randBits(numOnes,maxNumber);
    System.out.println("\n--Test for #ones: " + numOnes + " max: " + maxNumber);
    for(int i=0;i<maxNumber;i++) System.out.println("--I: " + i + " bit: " + bitsBack[i]);
    } //--end main
    } //--end shuffle bits
    The output was.
    --Test for #ones: 5 max: 15
    --I: 0 bit: 0
    --I: 1 bit: 1
    --I: 2 bit: 0
    --I: 3 bit: 0
    --I: 4 bit: 1
    --I: 5 bit: 0
    --I: 6 bit: 0
    --I: 7 bit: 0
    --I: 8 bit: 0
    --I: 9 bit: 1
    --I: 10 bit: 0
    --I: 11 bit: 0
    --I: 12 bit: 1
    --I: 13 bit: 1
    --I: 14 bit: 0
    --Test for #ones: 12 max: 15
    --I: 0 bit: 1
    --I: 1 bit: 1
    --I: 2 bit: 0
    --I: 3 bit: 0
    --I: 4 bit: 1
    --I: 5 bit: 1
    --I: 6 bit: 0
    --I: 7 bit: 1
    --I: 8 bit: 1
    --I: 9 bit: 1
    --I: 10 bit: 1
    --I: 11 bit: 1
    --I: 12 bit: 1
    --I: 13 bit: 1
    --I: 14 bit: 1
    --Test for #ones: 12 max: 15
    --I: 0 bit: 1
    --I: 1 bit: 1
    --I: 2 bit: 0
    --I: 3 bit: 1
    --I: 4 bit: 1
    --I: 5 bit: 0
    --I: 6 bit: 1
    --I: 7 bit: 1
    --I: 8 bit: 0
    --I: 9 bit: 1
    --I: 10 bit: 1
    --I: 11 bit: 1
    --I: 12 bit: 1
    --I: 13 bit: 1
    --I: 14 bit: 1
    --Test for #ones: 12 max: 15
    --I: 0 bit: 1
    --I: 1 bit: 1
    --I: 2 bit: 1
    --I: 3 bit: 1
    --I: 4 bit: 1
    --I: 5 bit: 1
    --I: 6 bit: 1
    --I: 7 bit: 0
    --I: 8 bit: 0
    --I: 9 bit: 1
    --I: 10 bit: 1
    --I: 11 bit: 1
    --I: 12 bit: 1
    --I: 13 bit: 0
    --I: 14 bit: 1
    notice the last few are the same sizes but come out in different order.
    --John Putnam                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • How to generate random sequence numbers

    Hello experts
    Iu2019m writing a custom program and pulling data from VBAK & VBAP. As per requirement I also need to generate a sequence number randomly and finally store all data in text file and upload at server. The hiccup is I donu2019t know how to generate sequence numbers. Can somebody please show me how I can accomplish it?
    Thanks a lot in advance

    Find the below code,
      data: lv_range type datatype-char0128.
      call function 'RANDOM_C'
        exporting
          len_min   = 20
          len_max   = 20
          char_min  = 1
          char_max  = 20
        importing
          rnd_value = lv_range.
    LV_RANGE param will have a random value..
    If you need number you can use the FM "RANDOM_I4"
    Thanks,
    Prathap

  • Generating 7 numbers random sequence

    Hello,
    create sequence centers_seq
    start with 1234567 increment by 1;
    This statement will create and start sequence from 1234567 and will increment by 1 whereas I am trying to generate random 7 digits and of course unique
    Thanks in anticipation
    Best regards

    Raakh wrote:
    I want to generate login ID but not in a sequence. The IDs are in 100's not more so I need to auto generate unique random IDs of 7 digitsWell, you can take a semi-random approach:
    SQL> create sequence s start with 100 maxvalue 999
      2  /
    Sequence created.
    SQL> select s.nextval * 10000 + trunc(dbms_random.value(1000,9999)) unique_semi_random_7_digit_num from dual
      2  /
    UNIQUE_SEMI_RANDOM_7_DIGIT_NUM
                           1007776
    SQL> /
    UNIQUE_SEMI_RANDOM_7_DIGIT_NUM
                           1017247
    SQL> /
    UNIQUE_SEMI_RANDOM_7_DIGIT_NUM
                           1025913
    SQL> /
    UNIQUE_SEMI_RANDOM_7_DIGIT_NUM
                           1033573
    SQL>  SY.

  • Project opens random sequences

    Hi,
    I have a documentary project with 8 sequences. I normally order the sequences (timelines) to my liking. But when I open the project it closes some and opens other sequences that I did not have open while last editing and saving the project.
    This is the only project that shows this behaviour, I have others where I can open and order the sequences to my liking and they open in the same order and have the same sequences open that I last used.
    Has anyone experienced this?

    OK, I chatted with Adobe and after they got back to me via email, here's what they wrote:
    "Hi Sami,
    This is Adobe Technical Support.
    We are responding in reference to your case# 0185837302 regarding the Adobe Premiere Pro, I researched the issue and found out that the issue is reproducible on our end.
    I have reported the issue to the higher level of support team. They will research on this issue and will try roll out a patch update to fix it."

  • [GS70] Some of my keyboard keys type a random sequence of characters

    On my GS70 when I press some keys it presses multiple keys, leading to weird behavior. I tested this with the macro functionality of the steelseries engine.
    When I press backspace it types: backspace + \ + reserved + reserved + F1 + Delete
    When I press comma it types: h + p + l + o + k + left alt + left shift + left control
    When I press the right arrow I get: right arrow + left arrow + up arrow + 1 + 5
    Basically my computer is unusable.
    If I would type this normally,hplok I would get weird results like thi#.
    Before reinstalling windows or sending the PC in for an RMA i'd like to know if anyone else has had this issue.
    thanks for your help!

    I have after getting the keyboard wet then it drying.

  • FCC a file with random sequence

    Hi Everybody,
       HI,
    I am facing one issue Can you tell me how i can resolve it. please see the incoming file structure i am getting
    010johnnewjersy
    02001price
    03002989
    030039898
    020011898
    02001101
    0309090
    010johnks
    where 010-keyfield
    020-keyfield
    030-keyfiled
    here rows with 020 030 can repeatand whole set 010,020..unbound,030..unbound . 010 record can repeat once again which will treated as new set
    hope you understand. need directions to configure my sender adapter. 
    Thanks for your time
    bye
    raj

    Hi,
    Pls do Content conversion in adapter as follows.
    Module Key            Parameter Name                 Parameter Value
    Plain2XML              xml.recordsetName               MyRecordset
    Plain2XML              xml.recordsetStructure           NameA,1,NameB,,NameC,
    Plain2XML              xml.keyFieldName                 MyKey
    Plain2XML              xml.keyFieldType                   CaseSensitiveString
    Plain2XML              xml.NameA.fieldNames          MyKey,field-nameA
    Plain2XML              xml.NameA.fieldFixedLengths  ex:2,10
    Plain2XML              xml.NameA.keyFieldValue       010
    Plain2XML              xml.NameB.fieldNames           MyKey,field-nameB1,field-nameB2
    Plain2XML              xml.NameB.fieldFixedLengths  ex:2,3,3
    Plain2XML              xml.NameB.keyFieldValue        020
    Plain2XML              xml.NameC.fieldNames            MyKey,field-nameC
    Plain2XML              xml.NameC.fieldFixedLengths   ex:2,5
    Plain2XML              xml.NameC.keyFieldValue        020
    It will solve your query.Please let me know if you still face problems.
    Please award marks if found useful.
    Thanks
    Hamja

  • How can I make my slideshow in iPOD shuffle correctly in a random sequence?

    When I choose the shuffle option for photos on my iPOD, it won't randomize all photos. (I have about 1,200 pics uploaded to my iPOD.) iPOD only shuffles the first few when viewed in the slideshow mode, it won't randomize from the entire directory. This is fairly frustrating, as I have removed and readded these pics several times to try and correct the problem with the same results. I have adjusted the slideshow options in everyway that I could think of, with the same results. I updated my iPOD with the lastest version of iTUNES and now i have gone back to the original version, but still the same result. Can someone help me? Please?

    just try the following:
    jsp.getVerticalScrollbar().setValue(0);after inserting and adding all your components. this will set the vertical scrollbar up to the very first line.
    regards

  • How can I manage the sequence of photos viewed on the Apple TV via i Tunes Home Share?  The photos in my directory are sequenced, they display in random order in the slide show.

    I am accessing a directory of photos on my network, using Home Share within iTunes.  The photos are displayed in random sequence, which is not helpful for an organized slide show.   Any ideas on sequencing the photos?

    Actually it appears that the sequence is likely by date/time.   Filename is DEFINITELY NOT the sequence.  I am trying to create a slideshow in iPhoto, fool the date problem by changing all dates to today, and sequencing by filename.  A very cumbersome process to an illogical problem, does not make sense to me at all.
    Thanks for trying to help.

  • Reading a Random Line from a Text File

    Hello,
    I have a program that reads from a text file words. I currently have a text file around 800KB of words. The problem is, if I try to load this into an arraylist so I can use it in my application, it takes wayy long to load. I was wondering if there was a way to just read a random line from the text file.
    Here is my code, and the text file that the program reads from is called 'wordFile'
    import java.awt.*;
    import java.awt.geom.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.io.*;
    import java.util.*;
    public class WordColor extends JFrame{
         public WordColor(){
              super("WordColor");
              setSize(1000,500);
              setVisible(true);
              add(new WordPanel());
         public static void main(String[]r){
              JFrame f = new WordColor();
    class WordPanel extends JPanel implements KeyListener{
         private Graphics2D pane;
         private Image img;
         private char[]characterList;
         private CharacterPosition[]positions;
         private int charcounter = 0;
         private String initialWord;
         private File wordFile = new File("C:\\Documents and Settings\\My Documents\\Java\\projects\\WordColorWords.txt");
         private FontMetrics fm;
         private javax.swing.Timer timer;
         public final static int START = 20;
         public final static int delay = 10;
         public final static int BOTTOMLINE = 375;
         public final static int buffer = 15;
         public final static int distance = 4;
         public final static Color[] colors = new Color[]{Color.red,Color.blue,Color.green,Color.yellow,Color.cyan,
                                                                          Color.magenta,Color.orange,Color.pink};
         public static String[] words;
         public static int descent;
         public static int YAXIS = 75;
         public static int SIZE = 72;
         public WordPanel(){
              words = readWords();
              setLayout(new BorderLayout());
              initialWord = getWord();
              characterList = new char[initialWord.length()];
              for (int i=0; i<initialWord.length();i++){
                   characterList[i] = initialWord.charAt(i);
              setFocusable(true);
              addKeyListener(this);
              timer = new javax.swing.Timer(delay,new ActionListener(){
                   public void actionPerformed(ActionEvent evt){
                        YAXIS += 1;
                        drawWords();
                        if (YAXIS + descent - buffer >= BOTTOMLINE) lose();
                        if (allColorsOn()) win();
         public void paintComponent(Graphics g){
              super.paintComponent(g);
              if (img == null){
                   img = createImage(getWidth(),getHeight());
                   pane = (Graphics2D)img.getGraphics();
                   pane.setColor(Color.white);
                   pane.fillRect(0,0,getWidth(),getHeight());
                   pane.setFont(new Font("Arial",Font.BOLD,SIZE));
                   pane.setColor(Color.black);
                   drawThickLine(pane,getWidth(),5);
                   fm = g.getFontMetrics(new Font("Arial",Font.BOLD,SIZE));
                   descent = fm.getDescent();
                   distributePositions();
                   drawWords();
                   timer.start();
              g.drawImage(img,0,0,this);
         private void distributePositions(){
              int xaxis = START;
              positions = new CharacterPosition[characterList.length];
              int counter = 0;
              for (char c: characterList){
                   CharacterPosition cp = new CharacterPosition(c,xaxis, Color.black);
                   positions[counter] = cp;
                   counter++;
                   xaxis += fm.charWidth(c)+distance;
         private void drawThickLine(Graphics2D pane, int width, int thickness){
              pane.setColor(Color.black);
              for (int j = BOTTOMLINE;j<BOTTOMLINE+1+thickness;j++){
                   pane.drawLine(0,j,width,j);
         private void drawWords(){
              pane.setColor(Color.white);
              pane.fillRect(0,0,getWidth(),getHeight());
              drawThickLine(pane,getWidth(),5);
              for (CharacterPosition cp: positions){
                   int x = cp.getX();
                   char print = cp.getChar();
                   pane.setColor(cp.getColor());
                   pane.drawString(""+print,x,YAXIS);
              repaint();
         private boolean allColorsOn(){
              for (CharacterPosition cp: positions){
                   if (cp.getColor() == Color.black) return false;
              return true;
         private Color randomColor(){
              int rand = (int)(Math.random()*colors.length);
              return colors[rand];
         private void restart(){
              charcounter = 0;
              for (CharacterPosition cp: positions){
                   cp.setColor(Color.black);
         private void win(){
              timer.stop();
              newWord();
         private void newWord(){
              pane.setColor(Color.white);
              pane.fillRect(0,0,getWidth(),getHeight());
              repaint();
              drawThickLine(pane,getWidth(),5);
              YAXIS = 75;
              initialWord = getWord();
              characterList = new char[initialWord.length()];
              for (int i=0; i<initialWord.length();i++){
                   characterList[i] = initialWord.charAt(i);
              distributePositions();
              charcounter = 0;
              drawWords();
              timer.start();
         private void lose(){
              timer.stop();
              pane.setColor(Color.white);
              pane.fillRect(0,0,getWidth(),getHeight());
              pane.setColor(Color.red);
              pane.drawString("Sorry, You Lose!",50,150);
              repaint();
              removeKeyListener(this);
              final JPanel p1 = new JPanel();
              JButton again = new JButton("Play Again?");
              p1.add(again);
              add(p1,"South");
              p1.setBackground(Color.white);
              validate();
              again.addActionListener(new ActionListener(){
                   public void actionPerformed(ActionEvent evt){
                        remove(p1);
                        addKeyListener(WordPanel.this);
                        newWord();
         private String getWord(){
              int rand = (int)(Math.random()*words.length);
              return words[rand];
         private String[] readWords(){
              ArrayList<String> arr = new ArrayList<String>();
              try{
                   BufferedReader buff = new BufferedReader(new FileReader(wordFile));
                   try{
                        String line = null;
                        while (( line = buff.readLine()) != null){
                             line = line.toUpperCase();
                             arr.add(line);
                   finally{
                        buff.close();
              catch(Exception e){e.printStackTrace();}
              Object[] objects = arr.toArray();
              String[] words = new String[objects.length];
              int count = 0;
              for (Object o: objects){
                   words[count] = (String)o;
                   count++;
              return words;
         public void keyPressed(KeyEvent evt){
              char tempchar = evt.getKeyChar();
              String character = ""+tempchar;
              if (character.equalsIgnoreCase(""+positions[charcounter].getChar())){
                   positions[charcounter].setColor(randomColor());
                   charcounter++;
              else if (evt.isShiftDown()){
                   evt.consume();
              else{
                   restart();
              drawWords();
         public void keyTyped(KeyEvent evt){}
         public void keyReleased(KeyEvent evt){}
    class CharacterPosition{
         private int xaxis;
         private char character;
         private Color color;
         public CharacterPosition(char c, int x, Color col){
              xaxis = x;
              character = c;
              color = col;
         public int getX(){
              return xaxis;
         public char getChar(){
              return character;
         public Color getColor(){
              return color;
         public void setColor(Color c){
              color = c;
    }

    I thought that maybe serializing the ArrayList might be faster than creating the ArrayList by iterating over each line in the text file. But alas, I was wrong. Here's my code anyway:
    class WordList extends ArrayList<String>{
      long updated;
    WordList readWordList(File file) throws Exception{
      WordList list = new WordList();
      BufferedReader in = new BufferedReader(new FileReader(file));
      String line = null;
      while ((line = in.readLine()) != null){
        list.add(line);
      in.close();
      list.updated = file.lastModified();
      return list;
    WordList wordList;
    File datFile = new File("words.dat");
    File txtFile = new File("input.txt");
    if (datFile.exists()){
      ObjectInputStream input = new ObjectInputStream(new FileInputStream(datFile));
      wordList = (WordList)input.readObject();
      if (wordList.updated < txtFile.lastModified()){
        //if the text file has been updated, re-read it
        wordList = readWordList(txtFile);
        ObjectOutputStream output = new ObjectOutputStream(new FileOutputStream(datFile));
        output.writeObject(wordList);
        output.close();
    } else {
      //serialized list does not exist--create it
      wordList = readWordList(txtFile);
      ObjectOutputStream output = new ObjectOutputStream(new FileOutputStream(datFile));
      output.writeObject(wordList);
      output.close();
    }The text file contained one random sequence of letters per line. For example:
    hwnuu
    nhpgaucah
    zfbylzt
    hwnc
    gicgwkhStats:
    Text file size: 892K
    Serialized file size: 1.1MB
    Time to read from text file: 795ms
    Time to read from serialized file: 1216ms

  • A simple question on random number generation?

    Hi,
    This is a rather simple question and shows my newbieness quite blatantly!
    I'm trying to generate a random number in a part of a test I have.
    So, I have a little method which looks like this:
    public int getRandomNumber(int number){
            Random random = new Random(number);
            return random.nextInt(number);
        }And in my code I do int random = getRandomNumber(blah)...where blah is always the same number.
    My problem is it always returns the same number. What am I missing here. I was under the impression that nextint(int n) was supposed to generate the number randomly!! Obviously I'm doing something wrong or not using the correct thing. Someone please point out my stupidity and point me in the right direction? Ta

    I think the idea is that Random will generate the same pseudo-random sequence over and over if you don't supply a seed value. (The better to debug with, my dear.) When you're ready to put an app into production, the seed value should be the current system time in milliseconds to guarantee a new sequence with each run.
    Do indeed move Random outside the loop. Think of it like a number factory - instantiate it once and let it pump out the random values for you as needed.

  • Problem with random number generation

    hey forum, i wonder if anyone can help me out with a small problem with my university coursework (yep its homework!!!)
    heres my problem, i am writing one of them 8 puzzle problems (the one based around sam lloyds 15 puzzler), i can successfully generate one random sequence of numbers with no duplicates, but whenever i call the random method again it keeps producing the same results
    heres the code
    in my main class file
    if(e.getSource() == randomButton) {
          new RandomPuzzle();
          System.out.println(random.randState);
          //startStateString = new RandomPuzzle();
    }heres my number generator class file
    import java.util.Random;
    import java.io.*;
    public class RandomPuzzle
         /** Base Random number generator */
        Random rn = new Random();
        /** Puzzle holder */
        byte b[];
        long number = 0;
        String randState = "";
        /** Default constructor */
        public RandomPuzzle() {
            rn.setSeed(number);
            b = new byte[9];
            randState = randomString();
        /** Provide range for generation */
        public int rand(int lo, int hi) {
            int n = hi - lo + 1;
            int i = rn.nextInt() % n;
            if (i < 0)
            i = -i;
            return lo + i;
        /** Set size for array */
        public int rand( int hi){
            int n = hi;
                return n;
        /** Check for duplicate values within the same configuration */
        boolean valueExists( byte value ) {
            int i = b.length;
            boolean exists = false;
            for( int j = 0; j < i; j++ ){
                if( b[j] == value )
                    exists = true;
            return exists;
        /** returns the actual string */
        public String randomString(int lo, int hi) {
            int n = rand( 9 );
            //boolean valueEntered = false;
            for (int i = 0; i < 9; i++) {
                boolean valueEntered = false;
                byte temp = (byte)rand('0', '8');
                while( valueEntered == false ) {
                    if( !valueExists( temp ) ) {
                         b[i] = temp;
                         valueEntered = true;
                    else
                        temp = (byte)rand('0', '8');
            return new String(b, 0);
        /** calls above function */
        public String randomString() {
            return randomString(0, 8);
    }i've tried for hours to work this out, but i am stumped. if anyone can point me in the right direction, maybe point out the problem code and give one or two tips i would be forever in your debt
    thanx in advance
    korbitz

    thanx for the help paulcw, but when i removed the seed code it done the same
    but i added this to my main class and now it works fine
    if(e.getSource() == randomButton) {
                   RandomPuzzle temp = new RandomPuzzle();
                   System.out.println(temp.randState);
                   //startStateString = new RandomPuzzle();
              }thanx again for your help

  • Create Slideshow Display sequence property doesn't work

    Create Slideshow Display sequence property doesn't work,
    I have selcted random but the slideshow always plays in order. I searched the scripts for any logi related to this and other properties set, but cannot find any refernce to any of these propoerties:
    transType='Random' transTime='1' firstImage='1' dispSequence='1'>
    How can I make the slideshow start  with a random image each time?
    thanks
    s

    Hello,
    I am back on this question, about how to get the non-flash version of the Creatr Slideshow v1.6 to display the images in a random sequence. Can anyone point me in the right direction, please?
    thanks
    juno

  • How do I rearrange the sequence of pictures within "All Photos" album?

    I've just upgraded to Photos. I have 35322 photos and it seems to handle it better than iPhoto.
    I'm finding the "All Photos" album is showing out of chronological sequence, with various "moments" photos intersperced into a variety of different "moments".
    I can't seem to find a way to rearrange the "All Photos" album to be a true chronological sequence, instead of the random sequence it has become.
    What am I missing?

    at top of listings the should be a heading "Track#" if not go to view, veiw options and tick track number the it will show on main screen click this new heading and the tracks should alter to the correct order. Hope this helps
    Windows XP
      Windows XP  

Maybe you are looking for