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

Similar Messages

  • What algorithm does Excel 2010 use for Pseudo Random Number Generation (MT19937?)

    Does Excel 2010+ use the Mersenne Twister (MT19937) algorithm for Pseudo Random Number Generation (PRNG), implemented by the RAND() function?
    This has been a nagging question for some time now, with "hints" that it indeed does.  However, a relatively thorough search turns up no definitive documentation.  The most direct indication is perhaps given by Guy Melard [Ref 9] where
    he tests Excel 2010's RAND() function using the Crush battery of tests in TestU01 by L'Ecuyer & Simard.  Melard references a "semi-official" indication that Microsoft did indeed implement MT19937 for the RAND() function in
    Excel 2010, but this reference no longer seems to be available. http://office.microsoft.com/enus/excel-help/about-solver-HP005198368.aspx?pid=CH010004571033.
    The other references below [Ref 1-10] document the history of the statistical suitability of the PRNG and probability distributions in various versions of Excel.  This includes the Wichmann-Hill PRNG implementations supposedly (arguably) used in
    Excel 2003 & 2007 for random number generation.  But still, we have no answer as to which PRNG algorithm is used in
    Excel 2010 (and 2013 for that matter).
    Microsoft indicates that RAND() has been improved in Excel 2010; Microsoft states, "...and the RAND function now uses a new random number algorithm." (see https://support.office.com/en-ca/article/Whats-New-Changes-made-to-Excel-functions-355d08c8-8358-4ecb-b6eb-e2e443e98aac). 
    But no details are given on the actual algorithm.  This is critical for Monte Carlo methods and many other applications.
    Any help would be much appreciated. Thanks.
    [Ref 1] B. McCullough, B. Wilson.  On the Accuracy of Statistical Procedures in Microsoft Excel 97. 
    Computational Statistics & Data Analysis. Vol. 31 No. 1, pp 27-37. July 1999.
    http://users.df.uba.ar/cobelli/LaboratoriosBasicos/excel97.pdf
    [Ref 2]L. Knüsel.  On the accuracy of the statistical distributions in Microsoft Excel 97. Computational Statistics & Data Analysis. Vol. 26 No. 3, pp 375-377. January 1998.
    http://www.sciencedirect.com/science/article/pii/S0167947397817562
    [Ref 3]B. McCullough, B. Wilson.  On the Accuracy of Statistical Procedures in Microsoft Excel 2000 and Excel XP. 
    Computational Statistics & Data Analysis. Vol.40 No. 4, pp 713-721. October 2002.
    https://www.researchgate.net/publication/222672996_On_the_accuracy_of_statistical_procedures_in_Microsoft_Excel_2000_and_Excel_XP/links/00b4951c314aac4702000000.pdf
    [Ref 4] B. McCullough, B. Wilson.  On the Accuracy of Statistical Procedures in Microsoft Excel 2003. 
    Computational Statistics & Data Analysis. Vol.49. No. 4, pp 1244-1252. June 2005.
    http://www.pucrs.br/famat/viali/tic_literatura/artigos/planilhas/msexcel.pdf
    [Ref 5] L. Knüsel. On the accuracy of statistical distributions in Microsoft Excel 2003. Computational Statistics & Data Analysis, Vol. 48, No. 3, pp 445-449. March 2005.
    http://www.sciencedirect.com/science/article/pii/S0167947304000337
    [Ref 6]B. McCullough, D.Heiser.  On the Accuracy of Statistical Procedures in Microsoft Excel 2007. 
    Computational Statistics & Data Analysis. Vol.52. No. 10, pp 4570-4578. June 2008.
    http://users.df.uba.ar/mricci/F1ByG2013/excel2007.pdf
    [Ref 7] A. Yalta. The Accuracy of Statistical Distributions in Microsoft<sup>®</sup> Excel 2007. Computational Statistics & Data Anlaysis. Vol. 52 No. 10, pp 4579 – 4586. June 2008.
    http://www.sciencedirect.com/science/article/pii/S0167947308001618
    [Ref 8] B. McCullough.  Microsoft Excel’s ‘Not The Wichmann-Hill’ Random Number Generators. Computational Statistics and Data Analysis. Vol.52. No. 10, pp 4587-4593. June 2008.
    http://www.sciencedirect.com/science/article/pii/S016794730800162X
    [Ref 9] G. Melard.  On the Accuracy of Statistical Procedures in Microsoft Excel 2010. Computational Statistics. Vol.29 No. 5, pp 1095-1128. October 2014.
    http://homepages.ulb.ac.be/~gmelard/rech/gmelard_csda23.pdf
    [Ref 10] L. Knüsel.  On the Accuracy of Statistical Distributions in Microsoft Excel 2010. Department of Statistics - University of Munich, Germany.
    http://www.csdassn.org/software_reports/excel2011.pdf

    I found the same KB article:
    https://support.microsoft.com/en-us/kb/828795
    This was introduced (according to the article) in Excel 2003. Perhaps the references in notes 2 and 3 might help.
    The article describes combining the results of 3 generators, each similar to a Multiply With Carry (MWC) generator, but with zero carry. MWC generators do very well on the Diehard battery of randomness tests (mentioned in your references), and have
    very long periods. But using zero carry makes no sense to me.
    Combining the three generators only helps if the periods of the 3 are relatively prime (despite what the article implies). Then the period of the result will be the product of the 3 periods. But without knowing the theory behind these generators, I have
    no idea what the periods would be. The formulas for MWC generators fail here.
    Richard Mueller - MVP Directory Services

  • HT204150 I'm having problems with random contacts disappearing from icloud. I have a saved text from a contact that displays her info but when I look for her in contacts it's missing.

    I'm having problems with random contacts disappearing from icloud. I have a saved text from a contact that displays her info but when I look for her in contacts it's missing.

    It is locked to your sisters carrier.
    She would have to ask her carrier if they unlock iPhones and if she qualifies for this service.

  • How to fill array with random number?

    I need to fill a 3-dimensional array that has user-controlled dimension sizes with random numbers (1-10). I'm unsure of how to do this. I feel like I have to use the initialize array and maybe the build array functions somehow but I'm not entirely sure. Any help would be appreciated. Thanks.

    Something like this
    Kudos are always welcome if you got solution to some extent.
    I need my difficulties because they are necessary to enjoy my success.
    --Ranjeet
    Attachments:
    Array with random number.vi ‏9 KB

  • Hello, i have a problem with this number code  213:19,  please help me!

    Hello, i have a problem with this number code  213:19,  please help me!

    dan
    What version of Premiere Elements and on what computer operating system is it running?
    If you are using Premiere Elements 13, have you updated it to 13.1 yet? If not, please do so using an opened project's Help Menu/Updates.
    What type of user account are you using....local administrator or domain type?
    Please review the following Adobe document on the 213.19 issue. Have you read that already?
    Error 213:19 | Problem has occurred with the licensing of this product
    ATR

  • Cannot contact the Adobe Service, I have a problem with the number.

    Hi,
    I would like to have more information in regard of the Adobe DC. My intent is to buy the product and use it in my office, we are a small company (4 PC).
    If I'm not wrong I should take the Standard Plan for Business, but I cannot arrange any payment request for information because I have a problem with the number I am supposed to call.
    Is there any other way to know if this software suit fine for me and my company, and most of all how much it will cost.
    Thank you for your consideration.
    Have a nice day!
    I look forward to hearing from you.
    Best,
    Augusto

    Hi Avgvstvs67,
    Please refer this link : https://acrobat.adobe.com/in/en/pricing/business-pricing.html
    Regards,
    Rahul

  • True Random number generation in OSX

    Hi there,
    I have been trying to find some information on how to access the Intel Random number generation hardware on my Mac.
    First I would like to understand which models currently offer this, second I would like to know if there is some library available I could use from either C or any other language, even from Applescript would be good for me.
    Thanks in advance.

    Perhaps these links help:
    http://www.intel.com/software/products/mkl/docs/mklnotes_mac.htm
    (keep in mind that apple typically discourages targeting specific hardware...)
    http://forums.macosxhints.com/showthread.php?t=46359
    http://www.mactricksandtips.com/2008/03/apple-script-random-number-generator.htm l

  • Problem with user number

    Goodmorning, I have a problem with user number of my smartphone Blackberry Curve 8900: when I call a numer of my adress book, on the right,  appears a user number, that I don't know. Why dont'appears mine? I don't have buy this smartphone personally, but I had it (used) through the smartphone's owner...I think that the user number that appears on my display is his. How I can do to remove it?
    Waiting for an answer, thank you.

    Hello scricciolina90
    Welcome To Support Forums
    On or Curve 8900 from the Home screen > click Options > Click Advanced Settings > SIM Card > Highlight the phone number > Press the Menu key and click Edit SIM Phone Number > Check that field or Enter you Mobile number in that field .
    Good luck.
    Click " Like " if you want to Thank someone.
    If Problem Resolves mark the post(s) as " Solution ", so that other can make use of it.

  • Random number generation with format 18XX88YYYYY

    I have been tryig to generate random numbers having
    format 18xx88yyyyy
    here
    18 followed by two random number then 88 followed by five random number. here 18 and 88 are fixed at location one,two,five and sixth position.
    but I am unable to get the logic .
    So please help
    Thanx
    Achyot

    After changing the column from number to varchar2 I am getting my correct result...
    create or replace function generateRandom return varchar2 is
    random varchar2(11);
    begin
    SELECT '18'|| lpad(ROUND (DBMS_RANDOM.VALUE (0, 100)),2,'0')|| '88'|| lpad(ROUND (DBMS_RANDOM.VALUE (0,
    100000)),5,'0')
    into random FROM DUAL;
    return random;
    end;
    create or replace procedure insertRandom is
    getNum varchar2(11);
    x number(3);
    cnt number;
    cursor checkpk is
    select random_no n from rand_no;
    begin
    cnt:=0;
    while (cnt<3054) loop
    x:=0;
    getNum:=generateRandom;
    for pkcheck in checkpk loop
    if getNum=pkcheck.n then
    x:=x+1;
    end if;
    end loop;
    if x=0 then
    insert into rand_no values(getNum);
    end if;
    select count(*) into cnt from rand_no;
    end loop;
    commit;
    end insertRandom;
    output:
    RANDOM_NO
    18388817929
    18658842315
    18028870847
    18898822037
    18678818255
    18248878003
    18558852407
    18878870907
    18998892135
    18538876212
    18908820740
    Thanx you everyone...

  • 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.

  • Packing instructions - problem with external number range

    Hi Gurus:
    I have a problem with configuring packing instructions. I have created a number range entry with external numbering (tx. OPIN), but when I want to create a new packing instruction in POP1, I get an error message: Manually-entered packing instruction ID cannot be checked (Message no. VHU01116). Can you please tell me how to avoid this error message?
    The system works fine if the number range is set to internal. As a matter of fact, initially I did create a setting with internal numbering and conducted a couple of tests, but I had to change the "external" flag in the number range to meet business requirements. Is it possible that somehow the system does not recognize that I have changed the flag and I need to run some generation program or something similar?
    I appreciate your valuable input
    Tamas

    For further records:
    we have found the problem after debugging the function. In order for the system to accept the external number range, a second number range object with ID 02 must be maintained in OPIN. Then you can use this number range as external and keep the first as internal.

  • Problems with random shutdown after replacing a swollen battery

    Hello all,
    Perhaps one of you can help with this issue.
    I'm using a Macbook Pro 17" mid-2007 model. A few months ago, the power disconnected from the machine when the battery had already run down and the machine did a hard shutdown. When I booted it back up there were serious problems with the display. Eventually it stopped working altogether. I took it for service and it was determined to by the NVIDIA graphics processor problem, so Apple replaced my motherboard.
    When I got the machine back from servicing, there was a rattle in the right fan that gradually got worse. After a while the touchpad button stopped depressing in the center. I also experienced several random shutdowns while operating on battery power. I learned about the swelling battery issue with macbooks and ordered a replacement. By the time the replacement battery arrived my original battery was quite swollen. I'm concerned that the swelling battery may have warped the case a bit, leading to the fan noise.
    I have now replaced the battery, but I'm still experiencing random shutdowns after 20+ minutes of use on battery power. I have done the RSS tests that were recommended in other forums and there doesn't seem to be any random shutdown problems when I'm plugged in -- only under battery power. My understanding is that a swelling battery can sometimes cause the battery to disengage from the electrical contacts on the MB, causing a sudden shutdown. I'm wondering why the problem is persisting now with a new battery? After one random shutdown, I tried to power up again using the battery, while pushing the battery into place at various angles, but I couldn't find any angle that would give power to the machine. The fan noise is also still present.
    Can anyone offer an explanation or advise on any methods to overcome these random shutdowns? I have checked the console and the machine isn't registering any error when it shuts down, although when it restarts it says "DirectoryService[35] Improper shutdown detected"

    Yep, it is video (or: or audio for video) so unless you're sure you need it (because you work or will work with the DVC Pro HD video/audio codec), you can remove the plug from its' folder and put it in your documents folder (don't trash it, I have no idea if it is necessary for non-DVC Pro HD users to have it installed too).
    The WWW is littered with posts from people encountering bugs and crashreports with DVCPROHDAudio.plugin as the main suspect. Most of those posts seem to be from video people rather than audio folks.
    http://www.google.nl/search?q=DVCPROHDAudio.plugin&ie=utf-8&oe=utf-8&aq=t&rls=or g.mozilla:en-US:official&client=firefox-a
    But, if you get crashes and you see this one mentioned in the report, disable it, restart, and see if the problem's gone.

  • Problem with Serial Number from MSi ATi HD4870 :/

    Hi all,
    I have problem with my HD4870. I lost the serial number (the small paper on back of card) from card. Have I any chance to get it back? I can take a photo and post it here some S/N and P/N from card, if it helpfull... I lose my warranty, if I can't get it back 
    So, any choice to get it?
    Thanks for answers,
    Mirek.

    Thanks for answers in first,
    I have problem with card - I had it two days in Crossfire with another HD4870 but accidentally when I played Metro 2033 I got some stripes on monitor (purple, blue) and then PC stop working. I had to restart PC and when the system booted to Windows, until 10 second I got the same stripes on monitor. Then my PC didn't boot.
    On my card I have 4 diodes - when I turned on pc, the diodes blinks but now blinks only TREE of FOUR diods.. So I took the card to shop when I bought it, but the shop-assistant told me, that I need this little paper on Card.. :/
    I'm from Czech Republic, so I have a little problem with directly contact to HQ of MSI
    So I have to go again to the shop and tell them, that Serial Numbers what they need are in card?

  • Problem with serial number and installing PSE 12

    I purchased Adobe PSE 12 yesterday and the purchase went through. But I never received a confoirmation email from Adobe. Now, when I try to enter the serial number to install, I'm told there is a problem with the serial number and I must contact customer support. Can't get through to customer support though. What should I do? I desperately need to get this program installed. Thanks.

    Hi 2Summers,
    Please provide me the serial number and I will check it for you.
    Send me aprivate message. Do not post it here.
    If you dont know how to do that refer : http://forums.adobe.com/thread/1184148

  • Problem with serial Number in Inspection Lot

    Dear All,
    I have a typical problem that material is there in quality inspection lot and serial numbers are aslo assigned during 101 mvt. but when I am posting it to unrestricted stock system is not determine serial number and giving an error
    *Stock data of serial number XXXXXX not suitable for movement
    Message no. IO231*
    All configuration setting are also OK as this problem comes for the first time and previously we were able to clear inspection lots of that material easily with serial number.
    Any Idea to rectify that problem?
    Thanks
    Edited by: Ashu on Aug 9, 2010 5:54 PM

    Hello,
    Check with your serializing Procedure check the assignment in Work scheduling View for this material also check in Quality view
    for inspection type 4 for GR of Production order.
    Regards,
    JayaVimal

Maybe you are looking for

  • Oracle 8.1.7 client install fails to run

    Hi, Hopefully someone else has seen this problem. I'm trying to install 8.1.7 client onto a Win2K SP2 machine, but I can't get the installer to run. There's no error message, no event logs or anything. I've also tried running the universal installer

  • Problem with T400 and External Display....

    I have a new T400 (less than 1 month old) with the shared memory Intel Graphics setup and I cannot get it to work with an external display of any kind. I've tried 2 LCD panels (one widescreen, and one 4:3), 2 analog monitors, and a video projector wi

  • If I had any more hair, I would be pulling it out

    iBook G4/1.42, 512MB RAM, 10.4.9 on combo update. Machine running absolutely fine. Been on 10.4.9 for some weeks. No problems whatsoever. Unaltered OS X apps in use. Regularly disk permissioned, cache cleaned, sudo periodic daily/weekly/monthly scrip

  • How do I make New window open maximized the way it used to?

    How do I make New window open maximized the way it used to?

  • Servers showing up multiple times in Sites and Services

    I happened to catch something odd this morning while looking into another issue.  When i open our domains Sites and Services and click on one of our 4 corporate DC's (3vm's one physical one of them being tested in production with server 2012 R2).  I'