Reg: Generating Random Integers:

Hi Experts,
Sorry for resurrecting my old thread - https://forums.oracle.com/message/10928049
Like Frank Kulash suggested (his last post in above thread):
As you probably noticed, the results discriminated against 1 and 9. That's because numbers were being rounded up or down to produce the integers 1 through 9, but no numbers were being rounded up to produce 1, and no numbers were rounded down to produce 9. A correct way to use ROUND would be
ROUND (dbms_random.value (.5, 9.5))
But surprisingly  I'm even getting values 1 & 9 for the below query :
SELECT ROUND(Dbms_Random.Value(1,9))
FROM dual
CONNECT BY LEVEL<=100;
Can any body please confirm the behavior?
-- Ranit
(Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production)

you can check it own:
select round(x), x
  from (SELECT Dbms_Random.Value(1, 9) x FROM dual CONNECT BY LEVEL <= 100)
1
1.00958727824362
1
1.35929462261339
1
1.07313087362894
1
1.39541607620187
1
1.08796277513722
1
1.43183190420528
1
1.09560186845415
2
2.35974832899944
2
2.3158341880934
2
1.52599047556987
2
2.37974359986276
2
2.30530327837917
2
1.8378556505608
2
2.41909513356704
2
1.74907912713616
2
1.72229810527042
2
2.1597745913138
2
2.06440750487121
2
2.0982190056438
2
2.0524769645307
3
3.35866001787213
3
3.14315892893997
3
2.53135843876159
3
3.23420560645603
3
3.15189114083364
3
2.97194582374213
3
2.73660206717264
3
2.69963724656505
3
3.21827931224339
4
4.15095159638964
4
4.16837167062646
4
3.72720254703438
4
3.5526690440214
4
3.55135374008975
4
4.19651566843293
4
4.36909714236384
4
3.56919854311661
4
3.89110676776102
4
4.0032340954152
4
3.53066148833693
4
4.13774817145481
4
3.86385674199289
4
4.30630900569414
4
3.98754993886356
4
4.43506599962048
5
4.54644810937981
5
5.27518693946758
5
4.93169654030369
5
4.68379021519564
5
5.4611403838419
5
4.71614031502033
5
4.93384285302108
5
5.07864957182936
5
4.72839176497723
5
4.85928177025523
5
4.53668745820041
5
4.97080767362867
6
5.61561080199998
6
5.85655646004377
6
6.1589737356415
6
6.46305497906528
6
5.54811527048922
6
6.30284273722328
6
6.30841844527289
6
6.40877037889211
6
6.14573053625073
6
5.79316621696824
6
5.51060861608968
6
5.88458765184622
6
5.68647227362169
6
5.58700573867026
6
6.22599345108297
7
7.4727041682604
7
7.38751225576785
7
7.49520896175461
7
6.73749527136869
7
7.46447932276796
7
6.57501612096089
7
7.13414219171924
7
6.93607163430359
7
6.52046182960753
7
7.2919103873137
7
6.74420595435779
8
8.43594139193597
8
7.68159185404298
8
8.01081476121886
8
8.41476778128371
8
8.45086248066315
8
7.83571427701249
8
7.71937441043553
8
7.86887882882576
8
8.39486930439563
8
7.83419765228732
8
8.42089354134024
8
7.71481978000627
9
8.68275277706912
9
8.75989388835502
9
8.811043149848
9
8.50885631647746
9
8.94065319543239
Ramin Hashimzade

Similar Messages

  • How does one generate random integers; first 5 values occur 2 times more than later values

    for the following code, how can I get the first 5 values to occur twice as often as the last 5 values?
    Do I have to use nested loops?
    Begin
      For n in 1 .. 10
      Loop
         dbms_output.put_line (ROUND(dbms_random.value(1, 10)));
    End Loop;
    End;

    Hi,
    If you had a lottery with 10 people participating, and you wanted to fix it so that each person had an equal chance of winning, what could you do?  One thing you could do is give tickets numbered 1, 2, 3, ..., 10 to the people, and then pick an integer in the range 1-10 at random.
    If you had a lottery with 10 people participating, and you wanted to fix it so that 5 of the people were twice as likely to win as the other 5, what could you do?  One thing you could do is to give 2 tickets to the first 5 people, but only 1 ticket to the other 5.  Since you have 15 tickets now, you'd pick a random integer in the range 1-15.
    Here's one way to do that in SQL.  The query below conducts 15 thousand lotteries.  We want the numbers 1-5 to get picked about 2000 times each, and the numbers 6-10 to occur about 1000 times each:
    WITH got_n AS
        SELECT  MOD ( TRUNC (dbms_random.value (0, 15))
                    , 10
                    ) + 1    AS n
        FROM    dual
        CONNECT BY LEVEL <= 15000
    SELECT    n
    ,         COUNT (*)    AS cnt
    FROM      got_n
    GROUP BY  n
    ORDER BY  n
    Sample output:
             N        CNT
             1       2048
             2       1939
             3       2020
             4       2066
             5       2007
             6        998
             7        967
             8       1004
             9        980
            10        971

  • Changing the size of list of random integers inside an array

    Hi. This is a small part of a bigger project about searching algorithms. Anyway, I need help with creating an array containing random integers. First, the array will generate a random list of 50 integers, then it will generate 51, etc. I know I have to put it in a for loop, but I don't know how to set up the array to get bigger after each pass.
    Here's what I have so far:
    for (int n=50; n<=500; n++){
    // Random number generator.
    Random generator = new Random();
    // Numbers in the range of 10 to 99.
    int randomNumber = 10 + generator.nextInt(99);
    /*This is the array that will contain the list of random
    numbers. Currently, it only generates 1 random
    number. How do I use the "n" in my for loop to control
    the size of my list of random numbers?*/
    int aa[] = {randomNumber};
    }Thanks!

    Array Size cannot be dynamically assigned, elseu
    need to use Vectors.The OP can create a new array each time.
    O_o
    Why would anyone want to do that?
    Vector is definitely the way to go!!Read the original question again:
    "This is a small part of a bigger project about searching algorithms"
    So the task is probably to test or implement seach algorithms that are searching within arrays. You can't use a Vector in that case.
    You probably also want to create new random data for each test, so the OP should do what he is trying to do. Create arrays of different lengths with different test data.
    >
    Or u can try tis logic..
    Create a string buffer put all the generatednumbers
    in the string seperated by a dash.
    Use string tokenizer and get the individualstrings
    and type cast them back to int(if you want)O_o
    Why would anyone want to do that?
    Consider it as a challenge of doin without
    collections and minimum memory utilization :-)System.arraycopy
    Kaj

  • How to generate random list of size n

    Hey its me again, my linked list implementation is working fine but i am having problems with one of the constructors of MyLLSet (a class which represents the linked list implementation of a set of integers)
    class must have two constructors : one which takes no
    arguments and creates an empty set (DONE)
    and another which takes a positive integer n as
    input and generates a set of size n with random elements (no duplicates) ,*problem comes in*, How do i generate a random list anyways? where do i get the random values from?
    again i am new to programming
    Here is my Node class that i created
    public class Node<Value> {
    Value element;
    Node<Value> next;
    Node(Value data)
                element=data;
                next=null;
            Node(Value data, Node n)
                element = data;
                next    = n;
    }and the question is how do i make the second constructor of MyLLSet
    private Node<Value> head;
    ..... // first constructor
    public MyLLSet(int n){
        head=?      ( how do i generate a random list of size n?)
    // implementation of methods form the interfacethanks
    Edited by: haraminoI on Mar 23, 2009 2:24 PM
    Edited by: haraminoI on Mar 23, 2009 2:25 PM
    Edited by: haraminoI on Mar 23, 2009 2:26 PM
    Edited by: haraminoI on Mar 23, 2009 2:26 PM
    Edited by: haraminoI on Mar 23, 2009 2:27 PM

    haraminoI wrote:
    doremifasollatido wrote:
    Keep the dummy if you want. It confused me (maybe because I hadn't seen it in ages, if ever), but if you understand it, the dummy is fine (it's apparently a standard way of writing linked lists).
    Generally, it is not advisable to call an overrideable (non-final with public, protected, or default [package-access] modifier) method from a constructor. But, if you disregard that advice for the moment, you could try calling 'add' with your nextInt, and repeat calling add until the size() of the set is n. That's certainly the easiest way to do it (otherwise, you'll have to repeat your 'add' code, with its check for duplicates, in the constructor).
    while (size of set < n) {
    add(new_random_int);
    }Your code for generating the random integers themselves is correct.
    Do you understand the above code?hey !
    Yes i understand that code, it probably is the easiest way,
    but when the random object generates a duplicate number, wont the add function output the duplicate error message?
    Edited by: haraminoI on Mar 23, 2009 5:11 PM
    public MyLLSet(int n){
        head=new Node(null);
        Node<Integer> p=head;
    Random R =new Random();
    int count=0;
    while(count<n){
        this.add(R.nextInt(n));
    count++;
    }And it works,
    but since my add function does nothing on duplicates,
    the code u mention doesnt reuturn a list of size n, because when the add method encounters a duplicate, it doesnt consider it, so the set size gets 1 node smaller, so if there are like 3 similar numbers generated form the random method, the set size become 3 nodes smaller,
    now how do i add three more non-duplicating nodes to the list
    below is my add method
    public void add(Integer v){
        Node<Integer> p;
        Node<Integer> q;
        p=head;
        while(p.next!=null){
            p=p.next;
        if(this.isIn(v)){
               // does nothing on duplicates
        else
        p.next=new Node(v,null);
    } thanks

  • How do you generate random data info using json and spry?

    I have a mobile applicaton that uses spry datasets that dynamically populate a jquery mobile listview by using a json file. Everything is operating as it should.
    However, I would like to understand how to pull random objects from the json file to have them displayed on a different page.
    My json file is standard and not complicated. It has several levels. Each is represented as below:
                                  { "Level1":
                                                                {"imageurl":"images/_myimage.png",
                                                                "someData":"S,A,P,R",
                                                                "levelLongDesc":"further description",
                                                                "name": "John Doe",
                                                                "page": "referencepage",
                                                                "description":"The description of the image"
    {"imageurl":"images/_myimage.png",
      "someData":"S,A,P,R",
      "levelLongDesc":"further description",
      "name": "John Doe",
      "page": "referencepage",
      "description":"The description of the image"
    Json file Level1 has about 70 objects
    What I would like to do is randomly load one of the Level1 object arrays into the page when the user selects a Level 1 radio button that is on the screen. I know how to create the page, radio buttons and basics, but just don't know how to pull in the random data.
    I've found one code sample on this site that speaks to spry and xml, but I haven't been able to apply it in any way that works for me with the json file:
    http://forums.adobe.com/message/662551
    I've also googled. There isn't much on spry datasets with json and generating random info. There was a little bit on sorting, but that didn't help either.
    Does anyone have a good example/tutorial of how to use the random function with spry/json?
    TIA
    -Rachel

    I've done similar things before.  A few thoughts for you:
    1. I'm assuming you're doing a buffered period or frequency measurement on the incoming encoder pulses, right?  First key point is that you'll have data that is spaced equally in position, but not equally in time.  If you are looking for a time-based FFT such that increasing speed will shift your spectrum, you're going to need to go through an interpolation process to resample your data as though equally-spaced in in time. 
    2. Your 149 pulse per rev encoder may be a significant source of error unless its 149 pulses are placed with extreme accuracy.  Any error in pulse placement violates your underlying assumption of data that is equally-spaced in position.  It'll be very helpful to send your data through a software lowpass filter to attenuate those artifacts. 
    3. I am not sure what you mean by "decompose the buffered data (array) into a single datastream."  You'll get an array of periods / frequencies from the call to DAQmx Read.  If you want to use it in a LabVIEW waveform datatype, you'll first need to do the resampling to create equally-spaced-in-time data.  The LabVIEW waveform datatype (and all the analysis functions like FFT that use it) depend on receiving data with a fixed constant time interval between samples.
    -Kevin P.

  • Generate random User Alias - Entity adapter

    Hi,
    I am a newbie. Can anyone please help me in telling steps for creating an Entity Adapter which generate a random User Alias.
    TIA.
    Got few threads that tell about pre-populate adapter, none for entity adapter.

    Hi,
    Follow the below steps to create new entity adapter in OIM
    To add the new created event handler to OIM server, perform the following steps:
    1. Write a java code to perform the needed operation ("Generate random user alias" in your case).
    2. Copy the file to OIM_HOME\xellerate\EventHandlers
    3. Open Design Console and navigate to: Development Tools -> Business Rule Definition -> Event Handler Manager
    4. Create a new Event Handler and specify:
    Event Handler Name: +<give the class name of your code>+
    Package: +<give the package name of your code>+
    Pre-Insert: Checked (for this scenario)
    5. Save the event handler
    6. Navigate to Development Tools -> Business Rule Definition -> Data Object Manager
    7. Search for "Users" and add the event handler to the Pre-Insert list.
    8. Save.
    Regards,
    NS

  • Need An Algorithm That Generates Random Numbers

    Hi, I understand that there is a built-in random number generator. But, I need an algorithm that generator random numbers. Is there one available? Thanks.

    Hi, is the "Seminumerical Algorithms" a book?What
    the numbers 3141592621 and 907633385 stand for?The first is PI without a decimal... the second I
    don't know, it may as well be randomly picked.As far as I know the numbers aren't randomly picked. You want the distribution to be good, and the length of the serie should also be long. Some numbers causes the cycle to be short, or the distribution to be bad. I think there are articles that lists 'good' numbers.
    /Kaj

  • I am unable to control my iPad 2. It is generating random letters when typing and when I try to delete it generates more letters unless I go slowly! Any advice?

    I am unable to control my iPad 2. When typing and deleting it generates random letters! Any advice

    Start with this and see how it goes. Quit all apps completely and reboot the iPad.
    Go to the home screen first by tapping the home button. Double tap the home button and the recents tray will appear with all of your recent apps displayed at the bottom. Tap and hold down on any app icon until it begins to wiggle. Tap the minus sign in the upper left corner of the app that you want to close. Tap the home button or anywhere above the task bar.
    Reboot the iPad by holding down on the sleep and home buttons at the same time for about 10-15 seconds until the Apple Logo appears - ignore the red slider if it appears on the screen - let go of the buttons. Let the iPad start up.

  • How to create a javabean that generate random password?

    May i know how to create a javabean that can generate random password?
    that include character and string
    and length of 10.

    i created a class file for my java bean
    package autogenerate;
    import java.util.*;
    public class GeneratePwId
    private int MemId;
    private String Passwd;
    public GeneratePwId(){}
    public String getPasswd()
    return this.Passwd;
    public void setPasswd()
    char[] letters = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
    'J', 'K', 'L', 'M', 'N', 'P', 'R', 'T',
    'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c',
    'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k',
    'm', 'n', 'p', 'q', 'r', 's', 't', 'u',
    'v', 'w', 'x', 'y', 'z', '0', '1', '2',
    '3', '4', '5', '6', '7', '8', '9' } ;
    String pwd = "" ;
    while( pwd.length() < 10 )
    pwd += letters[ (int)( Math.random() * letters.length ) ] ;
    this.Passwd = pwd;
    i successfully compile my java file. and try to test it by writing a jsp file.
    here is my jsp code
    <html>
    <head>
    <title>
    Try retrieving password
    </title>
    </head>
    <body>
    <jsp:useBean class"autogenerate.GeneratePwId" id="bean0" scope="page"/>
    <%=bean0.getPasswd()%>
    </body>
    </html>
    but i encounter this error
    org.apache.jasper.compiler.ParseException: /jsp/GetPasswd.jsp(7,18) Attribute class has no value
    anyone can teach me how to solve this problem?
    thanks a alot!

  • Please help to write a java code for generate Random numbers

    I need a program for generate Random integer numbers by using roulette wheel theory. I search several ares, but I'm unable to find out at lease a Pseudo code for implement this. If you know or have a code for this, Please send me a mail to [email protected] or post here.

    Gagana wrote:
    I need a program for generate Random integer numbers Have a look at the java.util.Random class:
    [http://java.sun.com/j2se/1.5.0/docs/api/java/util/Random.html]
    Or Google:
    [http://www.google.com/search?q=random+java]
    by using roulette wheel theory. What is that?
    ... Please send me a mail to [email protected]
    No, that defeats the purpose of a public forum. And no one is going to e-mail you (other than someone trying to sell V1AGRA).

  • Generate random number and letter in a text field ...

    Hi All,
    I having a bit trouble when trying to generate random number and letter in application express in a text field. Say I have a licence form and when user wants to create a licence, it will provide a random licence number in the licence number field but it has to be unique. the number should be something like HQ2345. I was trying to set the following sql in default value for that text field but it is not working -
    select DBMS_RANDOM.STRING('',2) || trunc(DBMS_RANDOM.VALUE(1000,9999))
    from dual;
    any suggesion !!!!
    thanks

    Put this as default value for your text-item
    DBMS_RANDOM.STRING('',2) || trunc(DBMS_RANDOM.VALUE(1000,9999))
    with type PL/SQL Expression. It have tested it and it works fine.
    DickDral

  • Generating Random Dollar values

    I need a section of code that will generate a random number (double) between 10000.00 and 10000000.00 for a tax program. What is the best way to do this?

    Math.random()*10000000.00 + 10000.00;:)) I thing you have neglected something... this generates random numbers between 10000.00 and 10010000.00...
    A correct thing would look like:
    double low = 10000;
    double high = 10000000;
    Math.random()*(high-low)+low;

  • Generate Random Number By sequence

    How to generate random 4 digit random number using sequence or any other method. Please suggest

    4 digit random numbers can be obtained by:
    SQL> SELECT TRUNC(DBMS_RANDOM.VALUE(1000,9999)) FROM DUAL;
    TRUNC(DBMS_RANDOM.VALUE(1000,9999))
                                   4002
    SQL> /
    TRUNC(DBMS_RANDOM.VALUE(1000,9999))
                                   4748
    SQL> /
    TRUNC(DBMS_RANDOM.VALUE(1000,9999))
                                   8328
    SQL> /
    TRUNC(DBMS_RANDOM.VALUE(1000,9999))
                                   3667
    SQL> /
    TRUNC(DBMS_RANDOM.VALUE(1000,9999))
                                   7464
    SQL> /
    TRUNC(DBMS_RANDOM.VALUE(1000,9999))
                                   4893
    SQL> /
    TRUNC(DBMS_RANDOM.VALUE(1000,9999))
                                   4961In mine case there is no repetition using Oracle 11.2.0.1 on Windows XP.
    Regards
    Girish Sharma

  • Generate Random number at VB6

    Thank you for reading below scenario:
    assume user will input 4 digits number to a text
    Input Number : 1119
    and I'll create a command button, after click on the command button it will generate above number
    Generate : 1119
    1191
    1911
    9111
    I did using "Randomize" but it generate the same number as result... .Can anyone give me an idea how to generate random number using Visual Basic as the above scenario?
    Thank's a lot

    The first thing to do is to rewrite in PHP.
    -- CJ

  • Generating random number within size of map problem (why me!!) ?

    Hi Guys,
    I'm trying to generator random numbers between 0 and a map width and another random number between 0 and a map height i.e if the map width was 3 i can generator 0,1,2.
    The coding i am using to do this is :
    int randomCol;
    int randomRow;
    randomCol = newMapWidth - 0 + 1;
    int itemp = generator.nextInt() % randomCol;
    if (itemp < 0)
          itemp = -itemp;
    randomCol = 0 + itemp;
    randomRow = newMapHeight - 0 + 1;
    int jtemp = generator.nextInt() % randomRow;
    if (jtemp < 0)
         jtemp = -jtemp;
    randomRow = 0 + jtemp;I've had a look at similar problems and searched penalty but can't seem to get it right for whatever way i implement. It leads to some array out of bound errors.
    If any can help me resolve this problem it would be greatly appreciated.
    Thanks A lot !

    Hippolyte wrote:
    randomRow = 0 + jtemp;I'll bite: what's the "0 + " voodoo for?It?s for clarity and Code readability, I guess. @OP: Random.nextFloat() generates numbers from 0.0f to 1.0f. Multiplying this number with your max value will generate a number between 0 and that given max value. BTW, you can generate numbers from -a to a by using (Random.nextFloat()- .5f) * (2 * a).
    Shazaam.

Maybe you are looking for

  • Battery doesn't charge on my newly purchased t500

    when i discover my new t500 is completely out of battery the first time, i immediately plugged it in to charge. i notice it doesn't charge, if i doble click power management it recognizes the battery but it doens't chaqrge no matter what i do with th

  • Problem in designing selection screen

    Hi friends............... Based on one radio button i need ti disable some Mandaory fields (those are Mandaory fields). But here i cant overcome these mandatory fields. How can i do this.

  • Import settings panel missing

    On selecting IMPORT, I frequently find that the panel at the right of the screen showing the destination and chosen import settings is completely blank. The only way I can get the panel back is to log off OS or restart - simply closing Aperture and r

  • HT1547 what does no good banks mean?

    hello. I have a macbook pro that when i turn it on it beeps 3 times then p. i know that this means no good banks, but what does that mean? is the RAM faulty?? It is second hand, but i got it from a trusted referbisher. I cant remember if he put new R

  • How to ip sent by mail preference from ipconfig

    Hello, I've tried to send me my ip by mail if it changes. But realised it send me local ip address. I used this command: ifconfig|grep inet|grep -v 127.0.0.1|grep -v inet6|cut -f2 -d" "|mail 'myemailaddresshere' How could i remove this one? I don't h