Zelaron Gaming Forum  
Stats Arcade Portal Forum FAQ Community Calendar Today's Posts Search
Go Back   Zelaron Gaming Forum > The Zelaron Nexus > Science and Art > Tech Help

 
 
Thread Tools Display Modes

 
Post C++ Randomity Help
Reply
Posted 2004-01-02, 01:32 AM
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
Old
Profile PM WWW Search
Randuin is neither ape nor machine; has so far settled for the in-between
 
 
Randuin
 



 
Reply
Posted 2004-01-02, 01:38 AM in reply to Randuin's post "C++ Randomity Help"
edit: sorry...i was wrong

Last edited by Demosthenes; 2004-01-02 at 01:48 AM.
Old
Profile PM WWW Search
Demosthenes seldom sees opportunities until they cease to beDemosthenes seldom sees opportunities until they cease to beDemosthenes seldom sees opportunities until they cease to beDemosthenes seldom sees opportunities until they cease to be
 
Demosthenes
 



 
Reply
Posted 2004-01-02, 01:42 AM in reply to Randuin's post "C++ Randomity Help"
nope, that's not it
Old
Profile PM WWW Search
Randuin is neither ape nor machine; has so far settled for the in-between
 
 
Randuin
 



 
Reply
Posted 2004-01-02, 02:15 AM in reply to Randuin's post "C++ Randomity Help"
hmmm What error are you gettting or what happens when you start it up? I dont feel like going and installing my complier.


Are you suggesting coconuts migrate?
Old
Profile PM WWW Search
Arbitus is neither ape nor machine; has so far settled for the in-betweenArbitus is neither ape nor machine; has so far settled for the in-between
 
 
Arbitus
 



 
Reply
Posted 2004-01-02, 02:24 AM in reply to Randuin's post "C++ Randomity Help"
Then don't bother posting
Old
Profile PM WWW Search
Randuin is neither ape nor machine; has so far settled for the in-between
 
 
Randuin
 



 
Reply
Posted 2004-01-02, 02:28 AM in reply to Randuin's post "C++ Randomity Help"
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


Are you suggesting coconuts migrate?
Old
Profile PM WWW Search
Arbitus is neither ape nor machine; has so far settled for the in-betweenArbitus is neither ape nor machine; has so far settled for the in-between
 
 
Arbitus
 



 
Reply
Posted 2004-01-02, 02:46 AM in reply to Randuin's post "C++ Randomity Help"
Oh boy you know alot of C++ then you should be able to figure this out dumbass
Old
Profile PM WWW Search
Randuin is neither ape nor machine; has so far settled for the in-between
 
 
Randuin
 



 
Reply
Posted 2004-01-02, 04:59 AM in reply to Randuin's post "C++ Randomity Help"
Give the int functions return values, or change the function type to void.
"Stephen Wolfram is the creator of Mathematica and is widely regarded as the most important innovator in scientific and technical computing today." - Stephen Wolfram
Old
Profile PM WWW Search
Chruser shouldn't have fed itChruser shouldn't have fed itChruser shouldn't have fed itChruser shouldn't have fed itChruser shouldn't have fed it
 
 
Chruser
 



 
Reply
Posted 2004-01-02, 10:11 AM in reply to Randuin's post "C++ Randomity Help"
I already told him to do that...it didn't work. Try a different parameter to srand...i dont know but that might help.
Old
Profile PM WWW Search
Demosthenes seldom sees opportunities until they cease to beDemosthenes seldom sees opportunities until they cease to beDemosthenes seldom sees opportunities until they cease to beDemosthenes seldom sees opportunities until they cease to be
 
Demosthenes
 



 
Reply
Posted 2004-01-02, 11:01 AM in reply to Randuin's post "C++ Randomity Help"
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.
"Stephen Wolfram is the creator of Mathematica and is widely regarded as the most important innovator in scientific and technical computing today." - Stephen Wolfram
Old
Profile PM WWW Search
Chruser shouldn't have fed itChruser shouldn't have fed itChruser shouldn't have fed itChruser shouldn't have fed itChruser shouldn't have fed it
 
 
Chruser
 



 
Reply
Posted 2004-01-02, 12:46 PM in reply to Randuin's post "C++ Randomity Help"
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?
Old
Profile PM WWW Search
Demosthenes seldom sees opportunities until they cease to beDemosthenes seldom sees opportunities until they cease to beDemosthenes seldom sees opportunities until they cease to beDemosthenes seldom sees opportunities until they cease to be
 
Demosthenes
 



 
Reply
Posted 2004-01-02, 02:00 PM in reply to Randuin's post "C++ Randomity Help"
Are you trying to get random numbers? i got a random number generator thta our gay teacher made us make....
Old
Profile PM WWW Search
Hades-Knight is neither ape nor machine; has so far settled for the in-between
 
 
Hades-Knight
 



 
Reply
Posted 2004-01-04, 11:47 AM in reply to Randuin's post "C++ Randomity Help"
EDIT:: This is Acer Posting, I didnt relize MarkiX logged on this computer

Chruser said:
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
Old
Profile PM WWW Search
MarkiX is neither ape nor machine; has so far settled for the in-betweenMarkiX is neither ape nor machine; has so far settled for the in-between
 
 
MarkiX
 



 
Reply
Posted 2004-01-04, 12:43 PM in reply to Randuin's post "C++ Randomity Help"
void statGen(int * stat){
srand ( (unsigned)time(NULL));
*stat=rand(); // or return srand(); and change return type to int
}
Old
Profile PM WWW Search
Mantralord seldom sees opportunities until they cease to beMantralord seldom sees opportunities until they cease to beMantralord seldom sees opportunities until they cease to beMantralord seldom sees opportunities until they cease to be
 
 
Mantralord
 



 
Reply
Posted 2004-01-04, 03:00 PM in reply to Randuin's post "C++ Randomity Help"
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
Old
Profile PM WWW Search
Randuin is neither ape nor machine; has so far settled for the in-between
 
 
Randuin
 



 
Reply
Posted 2004-01-07, 11:40 AM in reply to Randuin's post "C++ Randomity Help"
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;
}
Old
Profile PM WWW Search
Acer enjoys the static noises of ten television sets simultaneously tuned to 412.84 MHzAcer enjoys the static noises of ten television sets simultaneously tuned to 412.84 MHz
 
 
Acer
 



 
Reply
Posted 2004-01-07, 03:24 PM in reply to Randuin's post "C++ Randomity Help"
paste me your results, i would HIGHLY doubt that they work fully
Old
Profile PM WWW Search
Randuin is neither ape nor machine; has so far settled for the in-between
 
 
Randuin
 



 
Reply
Posted 2004-01-08, 07:29 AM in reply to Randuin's post "C++ Randomity Help"
Try this:

10011010011101001010100011010101010001101010011101 10001110010100010011010110010100110100111010010101 00011010101010001101010011101100011100101000100110 10110010100110100111010010101000110101010100011010 10011101100011100101000100110101100101001101001110 10010101000110101010100011010100111011000111001010 00100110101100101001101001110100101010001101010101 00011010100111011000111001010001001101011001010011 01001110100101010001101010101000110101001110110001 110010100010011010110010
Old
Profile PM WWW Search
DazIsBack is neither ape nor machine; has so far settled for the in-betweenDazIsBack is neither ape nor machine; has so far settled for the in-between
 
DazIsBack
 
 

Bookmarks

« Previous Thread | Next Thread »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules [Forum Rules]
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -6. The time now is 10:00 AM.
'Synthesis 2' vBulletin 3.x styles and 'x79' derivative
by WetWired the Unbound and Chruser
Copyright ©2002-2008 zelaron.com
Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
This site is best seen with your eyes open.