Wrox Programmer Forums
|
C++ Programming General discussions for the C++ language. For questions specific to Microsoft's Visual C++ variant, see the Visual C++ forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C++ Programming section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old November 3rd, 2006, 11:24 AM
Registered User
 
Join Date: Nov 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default C++ randomizing

I can't really fully understand randomizing in C++, can anyone please just put in the code to randomise getting an int number between 1 and 6, plz, i know how to do it with doubles and similar stuff, but i just can't get this.

http://img126.imageshack.us/img126/2...r115497yv7.gif
Reply With Quote
  #2 (permalink)  
Old November 17th, 2006, 08:16 AM
Friend of Wrox
 
Join Date: Jan 2006
Posts: 103
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via AIM to Geo121
Default

Please keep in mind that complete and truthful randomness is impossible to calculate
Instead when a number is artificially randomized then it becomes part of a large almost hidden pattern
But sooner or later the numbers will repeat themselves in the same pattern

This is the best random function I have ever designed
yet it is extremely flawed due to it's required positive values
but if you had a negative number that you wanted to include just find the RANGE (biggest number minus smallest number) and do a random for 0 to that and then subtract the deficate example below

int random(unsigned short int start, unsigned short int finish)
{
    srand((unsigned)time(0));
    int rint;
    rint = (rand()%(finish+1)) + start;
    return rint;
}

just enter in the start and finish numbers to get your random number
so random number 1 to 6 :

random(1, 6);

so random number -6 to 3 :

int randInt = random(0, 9);
randInt -= 6;

~ Geo

 ~ You are unique, just like everyone else
Reply With Quote





Similar Threads
Thread Thread Starter Forum Replies Last Post
Randomizing hcweb Classic ASP Basics 4 April 21st, 2004 11:31 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.