![]() |
C++ Randomity Help
Code:
#include <iostream> |
edit: sorry...i was wrong
|
nope, that's not it :)
|
hmmm What error are you gettting or what happens when you start it up? I dont feel like going and installing my complier.
|
Then don't bother posting
|
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
|
Oh boy you know alot of C++ then you should be able to figure this out dumbass
|
Give the int functions return values, or change the function type to void.
|
I already told him to do that...it didn't work. Try a different parameter to srand...i dont know but that might 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.
|
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? |
Are you trying to get random numbers? i got a random number generator thta our gay teacher made us make....
|
EDIT:: This is Acer Posting, I didnt relize MarkiX logged on this computer
Quote:
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 |
void statGen(int * stat){
srand ( (unsigned)time(NULL)); *stat=rand(); // or return srand(); and change return type to int } |
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 |
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; } |
paste me your results, i would HIGHLY doubt that they work fully
|
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.