• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.

Archived

This topic is now archived and is closed to further replies.

Metal Typhoon

Stdlib.h

20 posts in this topic

I''m using Vc++ and i included the stdlib.h . But i''m trying to generate a random number but it does. I do this: short Test; Test = random(10); cout <<"Test"< How can i generate a random number in vc++ ? Thank''s "The shortcut is not always the best way " Metal Typhoon
0

Share this post


Link to post
Share on other sites
i''ve tried that , look what it turn back to me

C:\Metal Softwares\Generator\Generator.cpp(23) : error C2660: ''rand'' : function does not take 1 parameters

and i did

rand(3);

Thanks

"The shortcut is not always the best way "

Metal Typhoon
0

Share this post


Link to post
Share on other sites
Sorry ... my mistake ...
rand() takes no parameters. It returns a number between 0 and RAND_MAX. So to generate a random number between 0 and 9, you would use 'rand() % 10'.

Edit: You'll also want to include time.h, and do a 'srand((unsigned int) time(0));'at the beginning of your program.

~~~~~~~~~~
Martee

Edited by - Martee on June 28, 2001 11:10:43 PM
0

Share this post


Link to post
Share on other sites
You should read carefully.

"C:\Metal Softwares\Generator\Generator.cpp(23) : error C2660: ''rand'' : function does not take 1 parameters"

And look into the help files more often.
This means no parameter...
So, it should be ...

Test = rand ( ); // rand ( empty )

Here is an example from the help files...

#include
#include
#include

void main( void )
{
int i;

/* Seed the random-number generator with current time so that
* the numbers will be different every time we run.
*/
srand( (unsigned)time( NULL ) );
// srand ( time ) to make it random based on time...
// or else u get the same number twice.

/* Display 10 numbers. */
for( i = 0; i < 10;i++ )
printf( " %6d\n", rand() );
}

"But why take the long way when the shortest is faster?"

BrownBean
0

Share this post


Link to post
Share on other sites
So if i just want to generate a random number between 0 2 i do this:

rand() % 3;

???

"The shortcut is not always the best way "

Metal Typhoon
0

Share this post


Link to post
Share on other sites
I have a vc++ version that i got on the internet so, i think that i can''t use the help.

Anyways i''ll buy the standard version, does that come with help stuff ?

"The shortcut is not always the best way "

Metal Typhoon
0

Share this post


Link to post
Share on other sites
this doesn''t work

  
#include <iostream>
#include <cstdlib>

int main()
{
// generate random number between 0 and 9

std::cout << std::rand() % 10 << std::endl;
return 0;
}

0

Share this post


Link to post
Share on other sites
This should work I did last one in c++ and
forgot the srand.

  
#include <stdio.h>

#include <stdlib.h>

#include <time.h>

int main(void)
{
srand(time(NULL));
printf("rand 0-9: %d\n", rand() % 10);
return 0;
}

0

Share this post


Link to post
Share on other sites
i got the rand() % 10; but i wanna know what does the srand(time(NULL)) does ?

And one more question if i buy vc++ standard does it come with any book ?

Thanks

"The shortcut is not always the best way "

Metal Typhoon
0

Share this post


Link to post
Share on other sites
>> I have a vc++ version that i got on the internet
Warezing a compiler!!

Yea you can go read www.msdn.microsoft.com but it''s
kind of unstructured.

for ansi standard c functions
http://www.tcnj.edu/~cs/doc/CStdLib.html
0

Share this post


Link to post
Share on other sites
This is getting a little hard without dodumentation. I''ve mostly used borland , now i''m going to Vc++ so i need a good vc++ begginers book and a c++ book , that is based in standard library.

Does anybody know any of those books there ?

"The shortcut is not always the best way "

Metal Typhoon
0

Share this post


Link to post
Share on other sites
quote:
Original post by Metal Typhoon
what does the srand(time(NULL)) does ?



It generates a new random number seed based on the current CPU time. This will ensure that numbers generated by rand() are actually somewhat pseudo-random. Just for fuy, try omitting that line, and then running your program a few times .

~~~~~~~~~~
Martee

Edited by - Martee on June 28, 2001 12:31:50 AM
0

Share this post


Link to post
Share on other sites
srand(time(NULL));

seeds the random number generator with the current time.

Computers can''t generate real random numbers (without getting some random input, like white noise). The rand() function generates a list of numbers based on a fairly complex algorithm, but it is actually ordered and generally it will give you the same sequence of numbers every time you call it (because the next number is based on what the last number is).

So, try writing a program that simple calls rand() 10 times and prints the results, run it a bunch of times. You''ll probably notice it spits out the same 10 numbers every time. Not very random right? srand allows you to ''seed'' the number generator. Using the current time is a fairly fast & somewhat randomish way of getting a unique starting point for the numbers, so that they appear to be more truly random.
0

Share this post


Link to post
Share on other sites
Yeah now i got it. Thanks

And a have a question . Is that part of the standard library ? If it''s can u tell me any book just about STL !!? Thanks again guys !!

"The shortcut is not always the best way "

Metal Typhoon
0

Share this post


Link to post
Share on other sites
rand() and srand() are parts of the standard C runtime library. Not the STL (which is C++ specific). A good book on C that covers the standard C runtime library is The C Programming Language by Kernighan & Ritchie. Considering they invented C, they know a thing or two about the language. Any bookstore with a good computer section (which is fairly rare, unfortunately) should have this. Or order online through B&N, or FatBrain.

A good book (well, books, really) on C++, including the STL is Bruce Eckel's Thinking in C++. You can even download this (in HTML or PDF format) which is very nice. Look here for more information:

http://www.mindview.net/Books

A lot of people also like the C++/STL books written by Scott Meyers. I don't personally have any experience with them, but considering how popular they are I'm guessing they are pretty good. Again, these books should be in most good bookstores or online bookstores.

Edited by - gmcbay on June 29, 2001 1:06:05 AM
0

Share this post


Link to post
Share on other sites
Thank''s man ! i really appreciate your help. I want to buy the STL, cuz i don''t like C as much as c++.

"The shortcut is not always the best way "

Metal Typhoon
0

Share this post


Link to post
Share on other sites
STL does a completely different job to the C run time libraries. STL is great for off-the-shelf linked lists, vectors, iterators and other template classes (hence the name standard template library) Im guessing that you havent learnt what templates are yet, (let alone linked lists, vectors and iterators) so forget about them for now, they are confusing and complicated and not something you want to jump into until you have the basics down (like being able to debug your own code for example)

Read your sig - dont try and learn to code the short way - you have to do it the long way. Get a basic beginners C/C++ book. Do the examples.
0

Share this post


Link to post
Share on other sites
( I removed my post as I was way off topic by the time I wrote it. )


"And that's the bottom line cause I said so!"

Cyberdrek
Headhunter Soft
A division of DLC Multimedia

Resist Windows XP's Invasive Production Activation Technology!

"gitty up" -- Kramer

Edited by - Cyberdrek on July 3, 2001 7:37:15 AM
0

Share this post


Link to post
Share on other sites