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.

Similar Messages

  • 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

  • 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

  • Random number within TWO ranges

    Is there anyway to select a random number within TWO ranges ? For example, a random number between the range (10 to 50) OR (100 to 200).
    Thank you !

    This is a simple class that produces a number between a range:
    class RandomRange
    static java.util.Random random= new java.util.Random();
    *    Return an int between n1 and n2
    static int getIntBetween(int n1, int n2) // n2 must be greater than n1 or n2-n1 must be positive
    // get random number between 0 and the range(n2 - n1)
    int result= random.nextInt(n2- n1);
    // plus the offset
    result += n1;
    return result;
    // return random.nextInt(n2 - n1) + n1;
    // the result is n2 exclusive, to make it inclusive return (result + 1)
    *    Return a double between d1 and d2
    static double getDoubleBetween(double d1, double d2)
    return random.nextDouble()*(d2 - d1) + d1;
    // d1 and d2 can be any value
    *    Return a float between f1 and f2
    static float getFloatBetween(float f1, float f2)
    // similar
    }----------------------------------

  • How to generate a random number within a specified tolerance and control that tolerance.

    I am trying to simulate data without using a DAQ device by using a random number generator and I want to be able to control the "range" of the random number generated though.  On the front pannel, the user would be able to input a nominal number, and the random number generator would generate numbers within plus or minus .003 of that nominal number.  The data would then be plotted on a graph.  Anyone know how to do this?  Or if it's even possible?
    Just for information sake, the random number is supposed to look like thickness measurements, that's why I want to simulate plus and minus .003 because the data could be thinner or thicker than the nominal.  
    Thanks in advance!!
    Solved!
    Go to Solution.

    You can create a random number with a gaussian probability profile using two equal distributed (0...1) random numbers and applying the Box Muller transform.
    I wrote one many years ago, her it is. (LabVIEW 8.0). 
    Message Edited by altenbach on 04-12-2010 09:13 PM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    BoxMuller.vi ‏10 KB

  • 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

  • Is there any way to generate random number in CPO

    Requirement : -
    > I want  to generate a random number from set of 1-9 numbers .is there any way in cpo ?
    Thanks
    Siva

    I created a process that uses 3 steps, all of which happen inside the engine rather than having to span out to a script, so it runs a lot faster.
    Technically, it's pseudo-random...
    Predefine Output Variable "Random Number" as type "Numeric"
    Step 1:  Format Date
      Format string: fffffff 
        (that's seven lower-case letters "f")
      Original date: [Process.Start Time]
    Step 2: Format Date
      Format string: ff\0\0\0\0\0
      Original date: [Process Start Time]
    Step 3: Set Variable
      Variable to update: [Process.Variables.Output.Random Number]
      New value: ([Workflow.Format Date.Formatted Date]-[Workflow.Format Date (2).Formatted Date])/100000
    This returns a basically random number between 0 and 1 (so you can mulitply it by your maximum value) based on the numeric fraction of a second of the start time of the process.

  • Need help with a JavaScript to generate random number

    Hi
    First things first. I don't know the J of JavaScript.
    When I was thinking of some readymade solution to generate a random number in Captivate, I found this on a LinkedIn forum.
    1) Add a user variable to your project called "randomNumber". It's value can be zero.
    2) Add a Text Caption with "$$randomNumber$$" in it, to check whether your script is working.
    3) Add a button to the slide. Give it an On Success Action of Execute JavaScript. Turn off it's "Continue Playing the Project" checkbox.
    4) Add the following text in the button's Script_Window:
    var objCP = document.Captivate;
    var rand = 1 + Math.floor(Math.random() * 10);
    function onButtonClick(){
    objCP.cpEISetValue('randomNumber', rand);
    onButtonClick();
    However, this is (as the poster in the forum warned) not working for Captivate 7. Can somebody please help?
    I am open for any other methods of getting the same result.
    Thanks in advance,
    Sreekanth

    Hi Sreekanth,
    When testing, make sure you are testing from a web server where the web address begins with http or https.  When setting the captivate variable "randomNumber" try this instead:
    objCP.cpEISetValue('m_VarHandle.randomNumber', rand);
    That will only work for SWF output.  If you want it to work for both HTML5 and SWF output, try this code:
    window.onButtonClick = function(){
              var rand = generateRandomNumber(1, 10);
              setCpVariable('randomNumber', rand);
    window.generateRandomNumber = function(min, max){
              var randomNum = 0;
              if(!isNaN(parseFloat(min)) && !isNaN(parseFloat(max))){
                        min = Number(min);
                        max = Number(max);
                  randomNum = Math.floor(Math.random() * (max - min + 1)) + min;
              return randomNum;
    window.setCpVariable = function (cpUserVariableName, variableValue) {
              /* Check for HTML5 vs. SWF output */
              if (typeof window.cp === 'undefined') {
                        /* We have SWF output, so Get the Captivate Object */
                        var objCp = document.getElementById('Captivate');
                        if (objCp && objCp.cpEISetValue) {
                                  /* Set the Captivate User variable with the JavaScript variable, variableValue */
                                  objCp.cpEISetValue('m_VarHandle.' + cpUserVariableName, variableValue);
              } else {
                        /* We have HTML5 output */
                        /*If variable does not exist off of the window object, then use the variables manager*/
                        if (typeof window[cpUserVariableName] === 'undefined') {
                                  if (cp.vm && cp.vm.setVariableValue) {
                                            cp.vm.setVariableValue(cpUserVariableName, variableValue);
                        } else {
                                  window[cpUserVariableName] = variableValue;
    window.onButtonClick();
    Be sure to test this from a web server or else local security will prevent the javascript from executing.
    Best,
    Jim Leichliter

  • Updating a field that generates random number when form is reset..

    I have a field that will generate a random number when the form is initially opened. THis fiekd runs an initialization script of : var randomnumber=Math.floor(math.random()*99999) and then a calculation script of randomnumber.
    The field value is set as Calculated - Read Only.
    When I hit the Reset button and it clears all the input fields for the form i would like to have it re calculate a new random number. I am not knowledgable in any scripting language and what I have so far I found by searching the forums.
    Any help would be appreciated.
    Thanks

    I don't know if it should matter, but the field to update is on a page other than the one with the reset button. And, the above is not working.
    I tried it as you stated above fieldname.rawvalue=randomnumber and I tried pagename.fieldname.rawvalue=randomnumber

  • Generate random number

    hi,
    can anybode give an example code
    how to generate a random number
    something like this:
    RandomData ran=RandomData.getInstance(...)
    byte[] ranString=JCSystem.makeTransientByteArray(...
    ran.generateData....
    and by the way can someone explain which line to put in which part of the code
    can I simply display this on a phone's screen with DisplayText proactive command ?
    regards
    Kuba

    i'm using Gemplus GXXv3 cards.
    And I'd like to display random data on the phone's screen using DISPLAY TEXT toolkit command.
    I just wonder if I have to convert the generated data somehow.
    Or can I just generate a byte array and display it using initDisplayText command.
    Kuba

  • 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

  • How to generate random number

    Hi I am trying to generate a random number between 0 to 100. Anyone know how to do this. I know we can use the Random class, but I don't know how to implement it between 0 and 100.
    Thanks

    XPOST:
    http://forum.java.sun.com/thread.jsp?forum=31&thread=547130&tstart=0&trange=15
    http://forum.java.sun.com/thread.jsp?forum=31&thread=547129&tstart=0&trange=15

  • Generating Random Number in NumberGuessing Game

    hi.. thankds for taking time to read this. please tell me how genNum works?
    public static void genNum followed by what coding? i have no idea. if possible please provide me with the necessary coding. thanks.

    I have never headr of genNum. If you want random numbers you want the following.....
    public class randomIntGenerator{
      private static long myRandom;
      private static long myMaximum;
      public static int getRandom(int maxValue){
        // Math.random() generates a random number between
        // 0 and 1.
        myRandom = Math.random();
        // To do the math you need your maximum as a long.
        myMaximum = new Long(maxValue).longValue();
        // multiply them together, then get the int value
        // and return it.
        return (new long(myRandom * myMaximum).intValue());
    }

  • Generating Random number for requisition number

    hai all,
    Am having a requirement of generating a random number based on the type of Process.
    Say if it is medical means I want it to be MEDxxxxx .
    Is thr any FM Please send some suggestions...
    Thanks in advance,
    Nalla.B

    Hi Nalla,
    First this is not WDABAP related question.
    To Do this you need to contact Functional guys, they will generate number ranges.
    Based on that object we can generate numbers. using NUMBER_RANGE_ENQUEUE and
    NUMBER_GET_NEXT  function module.
    Cheers,
    Kris.

  • Generate Random number-Dynamic.

    Guys,
    I'm looking for a pl\sql block to generate a 10 digit random number.
    Could someone help me out?
    Also, is there anyway to make it dynamic?..ie.If i pass 4 to the procedure\function, it should generate a 4 digit number..Thoughts please?
    Regards,
    Bhagat

    Please read about [url http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_random.htm#sthref4646]DBMS_RANDOM in the manual.

Maybe you are looking for

  • Hp dj 2510 how to print on a A9 envelope

    Hi,  I have a HP DJ 2510 as a utility printer - on the advanced setting there is no A9 envelope listing, but lots of weird japanese speciality settings. First, do I have the correct software? If so, how do I get it to print on a fairly common sized A

  • AxAcroPDFLib.AxAcroPDF fails with MS Visual Studio Pro 2013

    Hello. I'm using MS Visual Studio Professional 2013 (Version 12.0.30501.00 Update 2) and MS .NET Framework Version 4.5.50938. I also have installed in my system (Windows 7 Home Premium - Service Pack 1) the Adobe Reader XI Version 11.0.07. Before 3 m

  • HOLD DOCUMENT NUMBER RANGE

    Hi. Is it possible to maintain the internal no range for Hold documents? Regards, Srini

  • Panorama photos too small

    Okay,so i have a cool panorama photo,but it's SO small,how would i make it bigger without messing up the quality(say i wanna put it in a long frame on my wall.)I know the video for the apple Itouch5 showed the kids in hallowen costumes and in a frame

  • Captured footage not accessable in FCPro but is in Quicktime

    This has happened twice now so I know its not just a fluke. A captured video was unplayable - unaccessible even - inside of FCPro 7. It acts like its 1 frame long rather than 27 minutes. But when I checked the file in scratch disk / captured / proj a