RNG using only system(); menu

Shout-Out

User Tag List

Results 1 to 10 of 10
  1. #1
    Iaccidentallytwink's Avatar Elite User
    Reputation
    591
    Join Date
    Aug 2007
    Posts
    1,020
    Thanks G/R
    1/16
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    RNG using only system();

    So I have a school assignment, I'm supposed to make an RNG in C++ using 1 - 300 that don't repeat. Obviously, this is, at the very least, an easy assignment (if not retarded). So, what I plan on doing is trolling them a bit, and make an RNG using only system(); to do ALL the calculations and outputs. Essentially, I'm writing the RNG in batch. Problem is, I can't find a working RNG. I currently have the following for my actual number calculations:
    Code:
    set /a X=%random%%300
    The problem with this is, using it multiple times in a row ALWAYS displays the same number. I'm stumped as to how to change this. I'm intent on sticking to using system only for it, and I'm wondering if anyone knew a way around this problem.

    +3 Rep to whoever helps me out.

    RNG using only system();
  2. #2
    Krillere's Avatar Contributor
    Reputation
    112
    Join Date
    Nov 2007
    Posts
    668
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm sorry, but what the hell is RNG?!

  3. #3
    MaiN's Avatar Elite User
    Reputation
    335
    Join Date
    Sep 2006
    Posts
    1,047
    Thanks G/R
    0/10
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Krillere View Post
    I'm sorry, but what the hell is RNG?!
    Random Number Generator.
    [16:15:41] Cypher: caus the CPU is a dick
    [16:16:07] kynox: CPU is mad
    [16:16:15] Cypher: CPU is all like
    [16:16:16] Cypher: whatever, i do what i want

  4. #4
    Krillere's Avatar Contributor
    Reputation
    112
    Join Date
    Nov 2007
    Posts
    668
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah ok. Thanks.

  5. #5
    Iaccidentallytwink's Avatar Elite User
    Reputation
    591
    Join Date
    Aug 2007
    Posts
    1,020
    Thanks G/R
    1/16
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Noone knows? It's due Wednesday >.>

  6. #6
    piller's Avatar Contributor
    Reputation
    82
    Join Date
    May 2007
    Posts
    103
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try something like this


    Code:
    #include <stdlib.h>
    int min=1,max=300,randomnum;
    
    int main(...) {
      init();
      ...
      do();
      do();
      return 0;
    }
    
    void init() {
      srand(time(NULL));
    }
    
    void do() {
      randomnum = min + rand()%(max-min+1);
    }
    and if you want to be sure none of the random numbers generated get repeated, put them in a stringlist or something like that and check the list every time you generate a new "random" number.

    but if you use the srand(time(NULL)); i dont think you´ll get same number twice ^^


    hope this helps
    Last edited by piller; 10-29-2009 at 02:16 PM.

  7. #7
    piller's Avatar Contributor
    Reputation
    82
    Join Date
    May 2007
    Posts
    103
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    omg. just saw the title : RNG using only system();


  8. #8
    Cypher's Avatar Kynox's Sister's Pimp
    Reputation
    1358
    Join Date
    Apr 2006
    Posts
    5,368
    Thanks G/R
    0/6
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    @The OP:
    You're doing it wrong.
    Last edited by Xel; 10-19-2011 at 01:27 AM. Reason: Retards do not exist when a helper ;)

  9. #9
    Iaccidentallytwink's Avatar Elite User
    Reputation
    591
    Join Date
    Aug 2007
    Posts
    1,020
    Thanks G/R
    1/16
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Cypher View Post
    @The OP:
    You're doing it wrong
    I know why it's generating the same number, of course.
    I was just wondering if there's anything I can do about it.
    Last edited by Xel; 10-19-2011 at 01:27 AM.

  10. #10
    RedArray's Avatar Corporal
    Reputation
    7
    Join Date
    Nov 2009
    Posts
    24
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    By now you have already turned this in and given up on this I'm sure. Not entirely sure if this will work as I haven't done EXACTLY what you are attempting to do using *shudder* system. But it's repeating the same number because "random" numbers are generated using the current time, and if you are asking it to produce numbers one immediately after the other it will always be the same until the time changes.

    So basically
    while(true)
    {
    system("whateverthehellyouaredoing");
    Sleep(100);
    }
    Probably have to increase the Sleep time to get a different number every time but the the concept still applies.

Similar Threads

  1. [new / rate] New Signature Using only Txt n c4d
    By XC4T4LY5TX in forum Art & Graphic Design
    Replies: 8
    Last Post: 07-15-2009, 12:21 AM
  2. [Guide] Uninstanced Sunwell Plateau (Using only Shadowstep)
    By morddrid in forum World of Warcraft Exploration
    Replies: 14
    Last Post: 05-13-2008, 07:12 AM
  3. Duplicate Gold.(one use only)
    By Equ1N0X in forum World of Warcraft Exploits
    Replies: 80
    Last Post: 06-26-2007, 10:02 PM
  4. Old IF using only a lvl 8 mage. NO MOUNT REQUIRED.
    By LiquidShizzles in forum World of Warcraft Exploration
    Replies: 13
    Last Post: 11-01-2006, 05:34 AM
All times are GMT -5. The time now is 03:00 PM. Powered by vBulletin® Version 4.2.3
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Google Authenticator verification provided by Two-Factor Authentication (Free) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search