C Question & Java Questions

Discussion in 'Software' started by e_f_w_a, Dec 8, 2004.

  1. e_f_w_a

    e_f_w_a Private E-2

    1. On C & Java - How can i make a size-limited random number (between 1-100 for example)?
    2. On Java - How can i use icons in JTextArea?
     
  2. Ciz

    Ciz Corporal

    Random number:
    Code:
    #include <cstdlib>
    #include <ctime>
    #include <iostream>
    
    int minVal = 1, maxVal = 100;
    srand(unsigned(time(NULL)));
    int RandomNumber;
        for(int i=0; i<10; i++)
        {
            RandomNumber =  minVal + rand() % (maxVal);
            cout << RandomNumber << endl;
        }
    
    
    sure there are other ways of doing it, but if I want one for whatever reason thats the way that I do it...

    Not sure about your other question...

    hope thats some help

    -All the best
    Ciz
     
  3. e_f_w_a

    e_f_w_a Private E-2

    why using loop for this? and what is that line with "<<" means?
     
  4. Ciz

    Ciz Corporal

    sorry, I usually want to generate more than one random number:
    Code:
    #include <cstdlib>
    #include <ctime>
    
    int minVal = 1, maxVal = 100;
    srand(unsigned(time(NULL)));
    int RandomNumber;
            RandomNumber =  minVal + rand() % (maxVal);
            cout << RandomNumber; //that just outputs it to the screen (just used one of my old peices of code) you dont need this...
    
    
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds