Zelaron Gaming Forum

Zelaron Gaming Forum (http://zelaron.com/forum/index.php)
-   Tech Help (http://zelaron.com/forum/forumdisplay.php?f=329)
-   -   C++ Randomity Help (http://zelaron.com/forum/showthread.php?t=26268)

Randuin 2004-01-02 01:32 AM

C++ Randomity Help
 
Code:

#include <iostream>
#include <windows.h>
#include <stdlib.h>
#include <time.h>

using namespace std;
struct player_stats {
    char name[25];
    int age;
    short str;
    short wis;
    short con;
} player;

int statGen(int stat)
{
    srand ( (unsigned)time( NULL ) );
    stat = rand();
}

int genChar(bool gender)
{
    if (gender == 1)
    {
    player.age = statGen(0);
    player.str = statGen(0) - 4;
    player.wis = statGen(0) + 4;
    player.con = statGen(0);
    }
    else
    {
    player.age = statGen(0);
    player.str = statGen(0) + 4;
    player.wis = statGen(0) - 4;
    player.con = statGen(0);
    }
    cout << "Your are " << player.age << " years old!\n";
    cout << "Your have " << player.str << " strength!\n";
    cout << "Your have " << player.wis << " wisdom!\n";
    cout << "Your have " << player.con << " constitution!\n";
}

int main(int argc, char *argv[])
{
    genChar(1);
    system("PAUSE");
    return 0;
}

It's not randoming :(

Demosthenes 2004-01-02 01:38 AM

edit: sorry...i was wrong

Randuin 2004-01-02 01:42 AM

nope, that's not it :)

Arbitus 2004-01-02 02:15 AM

hmmm What error are you gettting or what happens when you start it up? I dont feel like going and installing my complier.

Randuin 2004-01-02 02:24 AM

Then don't bother posting

Arbitus 2004-01-02 02:28 AM

OMFG what a little girl. I try helping you cuz i know alot of C++ and you dont even want it. I dont care. Aint hurting me any. lol

Randuin 2004-01-02 02:46 AM

Oh boy you know alot of C++ then you should be able to figure this out dumbass

Chruser 2004-01-02 04:59 AM

Give the int functions return values, or change the function type to void.

Demosthenes 2004-01-02 10:11 AM

I already told him to do that...it didn't work. Try a different parameter to srand...i dont know but that might help.

Chruser 2004-01-02 11:01 AM

Strange, it worked just fine for me. You shouldn't have edited out your post if you're wrong, as a solution that doesn't work could lead to one that DOES work.

Demosthenes 2004-01-02 12:46 PM

well...when i run it i get:

Your are 21406 years old!
Your have 21402 strength!
Yoyr have 21410 wisdom!
Your have 21406 constitution!




is that what you want or do you want each of the statGen(calls) to give you a completely random number other than the same one each time?

Hades-Knight 2004-01-02 02:00 PM

Are you trying to get random numbers? i got a random number generator thta our gay teacher made us make....

MarkiX 2004-01-04 11:47 AM

EDIT:: This is Acer Posting, I didnt relize MarkiX logged on this computer

Quote:

Originally Posted by Chruser
Give the int functions return values, or change the function type to void.

yes this function has no return...

int statGen(int stat)
{
srand ( (unsigned)time( NULL ) );
stat = rand();
}

you are also can assign a value to stat, you cant unless its a *pointer]

so you could do this...

void statGen(int* stat)
{
srand ( (unsigned)time(NULL) );
stat = rand();
}


that should be right... dont have VC++ to test sorry

Mantralord 2004-01-04 12:43 PM

void statGen(int * stat){
srand ( (unsigned)time(NULL));
*stat=rand(); // or return srand(); and change return type to int
}

Randuin 2004-01-04 03:00 PM

return doesn't do shiat....

it's just that I could only seed the random function once, other wise it'll always return the same value

Acer 2004-01-07 11:40 AM

I got VS6 and compiled this and it worked... tho the values were high



#include <iostream>
#include <windows.h>
#include <stdlib.h>
#include <time.h>

using namespace std;
struct player_stats {
char name[25];
int age;
short str;
short wis;
short con;
} player;

int statGen(int stat)
{
srand ( (unsigned)time( NULL ) );
stat = rand();
return stat; //returns value now
}

void genChar(bool gender) //VOID now not INT
{
if (gender == 1)
{
player.age = statGen(0);
player.str = statGen(0) - 4;
player.wis = statGen(0) + 4;
player.con = statGen(0);
}
else
{
player.age = statGen(0);
player.str = statGen(0) + 4;
player.wis = statGen(0) - 4;
player.con = statGen(0);
}
cout << "Your are " << player.age << " years old!\n";
cout << "Your have " << player.str << " strength!\n";
cout << "Your have " << player.wis << " wisdom!\n";
cout << "Your have " << player.con << " constitution!\n";
}

int main(int argc, char *argv[])
{
genChar(1);
system("PAUSE");
return 0;
}

Randuin 2004-01-07 03:24 PM

paste me your results, i would HIGHLY doubt that they work fully

DazIsBack 2004-01-08 07:29 AM

Try this:

10011010011101001010100011010101010001101010011101 10001110010100010011010110010100110100111010010101 00011010101010001101010011101100011100101000100110 10110010100110100111010010101000110101010100011010 10011101100011100101000100110101100101001101001110 10010101000110101010100011010100111011000111001010 00100110101100101001101001110100101010001101010101 00011010100111011000111001010001001101011001010011 01001110100101010001101010101000110101001110110001 110010100010011010110010


All times are GMT -6. The time now is 11:33 PM.

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
This site is best seen with your eyes open.