rand() function? menu

Shout-Out

User Tag List

Results 1 to 7 of 7
  1. #1
    klamor's Avatar Active Member
    Reputation
    30
    Join Date
    Mar 2007
    Posts
    323
    Thanks G/R
    0/0
    Trade Feedback
    1 (100%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    rand() function?

    So one of my assignments in my programming class is to make a program that will generate 5 random cards (from a deck)...

    i searched some sites off of google, but none of them really helped me. i'm just looking for what i need to include to use this function and what the syntax is... thanks


    rand() function?
  2. #2
    schlumpf's Avatar Retired Noggit Developer

    Reputation
    755
    Join Date
    Nov 2006
    Posts
    2,759
    Thanks G/R
    0/3
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    srand ( time(NULL) );
    int onetofive = rand( void ) % 5 + 1;

    protip: "c++ rand". or just go to http://www.cplusplus.com/reference/c.../cstdlib/rand/ yourself.

  3. #3
    Confucius's Avatar Super Moderator Don't Look Back in Anger

    CoreCoins Purchaser Authenticator enabled
    Reputation
    1418
    Join Date
    Oct 2007
    Posts
    2,799
    Thanks G/R
    300/311
    Trade Feedback
    7 (100%)
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I actually have code for a program that does this exact thing but for a dice so if you want to know the code pm me

  4. #4
    Cromon's Avatar Legendary


    Reputation
    840
    Join Date
    Mar 2008
    Posts
    714
    Thanks G/R
    0/7
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by schlumpf View Post
    srand ( time(NULL) );
    int onetofive = rand( void ) % 5 + 1;
    Do not use % (modulus) to limit the random numbers generated. The randomness is heavily reduced.
    Code:
    inline unsigned int random(unsigned int high)
    {
    	return unsigned int(((rand() / float(RAND_MAX)) * high) + 0.5);
    }

  5. #5
    Xel's Avatar ★ Elder ★
    Authenticator enabled
    Reputation
    1179
    Join Date
    Jul 2008
    Posts
    2,906
    Thanks G/R
    94/51
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    x = rand()%(maxvalue-minvalue)-minvalue;

    so if you wanted a number between 13 and 200 it would be

    x = rand()%(200-13)-3;

    Basically it does this:
    1) Random number, lets say 2331
    2) Divide with 200-13 which is 187
    3) Answer 12 remainder 2331-(12*187)= 87
    4) Random number is the remainder so it's 87.

  6. #6
    Cromon's Avatar Legendary


    Reputation
    840
    Join Date
    Mar 2008
    Posts
    714
    Thanks G/R
    0/7
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    1. Do not use % !!! you just ****ing kill randomness (search google for articles about that).

    2. x = unsigned int(((rand() / float(RAND_MAX)) * (maxval - minval) + 0.5) + minval;

  7. #7
    Xel's Avatar ★ Elder ★
    Authenticator enabled
    Reputation
    1179
    Join Date
    Jul 2008
    Posts
    2,906
    Thanks G/R
    94/51
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh, I understand..

    Well, do as Cromon states.

Similar Threads

  1. [Release] Scan Pixels function for VB.net
    By suicidity in forum World of Warcraft Bots and Programs
    Replies: 6
    Last Post: 07-09-2014, 02:12 PM
  2. item Teleport [completed and functional]
    By venom9122 in forum World of Warcraft Emulator Servers
    Replies: 15
    Last Post: 12-13-2007, 11:46 PM
  3. [Release]Blizzlike Database - Fully Functioning
    By ~SaiLyn~ in forum World of Warcraft Emulator Servers
    Replies: 17
    Last Post: 11-12-2007, 09:52 PM
  4. Function locating.
    By HolyForce in forum World of Warcraft General
    Replies: 0
    Last Post: 03-03-2007, 07:19 AM
All times are GMT -5. The time now is 03:21 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