Thread: increasing prob with randoms

  1. #1
    Registered User scuba22's Avatar
    Join Date
    Oct 2002
    Posts
    35

    increasing prob with randoms

    Hi, I need to be pointed towards the correct way to express,
    a greater percent chance of something happending.
    For example:

    a and b are playing cards and a has a 60% chance of winning.
    and the wins are generated by rand.(got that part) it's just
    the percentages
    Thanks
    Michele

  2. #2
    Green Member Cshot's Avatar
    Join Date
    Jun 2002
    Posts
    892
    One easy way is to generate random numbers from 1-100. Anything from 1-60 inclusive would mean a wins, and anything else means b wins.
    Try not.
    Do or do not.
    There is no try.

    - Master Yoda

  3. #3
    Just a Member ammar's Avatar
    Join Date
    Jun 2002
    Posts
    953
    The random number will always be random, so you need to make the condition like what Cshot said...

  4. #4
    Registered User scuba22's Avatar
    Join Date
    Oct 2002
    Posts
    35
    i neeed something
    a little more specific
    i thought i could do something like this:

    Code:
    #include<iostream>
    #include<cstdlib>
    #include<ctime>
    #include<iomanip>
    #include<iostream>
    #include<fstream> 
    using namespace std;
    
    
    		//function prototype
    			int pp (int);
    			int score = 0;
    
    		void main()
    		{
    
    			ofstream outfile("A:\\0F1017_6_2.txt"); 
    			if(!outfile){ 
    				cerr << "Cannot open output file" << endl; 
    			  
    		} 
    	
    			srand((unsigned) time(0));
    			int a = 0(.56);
    			int b = 0(.44);
    			int aa = 0;
    			int bb = 0;
    where i assigned the percentages to a and b.
    it seems to work....
    what do you think?
    michele

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Deal or No Deal listbox prob
    By kryptkat in forum Windows Programming
    Replies: 5
    Last Post: 03-30-2009, 06:53 PM
  2. Problem with Dynamically Increasing Array of Integers
    By laserlight in forum C++ Programming
    Replies: 30
    Last Post: 07-04-2008, 07:27 AM
  3. little prob with string?
    By ghostshadow189 in forum C++ Programming
    Replies: 6
    Last Post: 04-22-2007, 02:02 PM
  4. prob with my cimple prog
    By KidMan in forum C Programming
    Replies: 3
    Last Post: 05-06-2006, 02:50 AM
  5. randoms...
    By Rune Hunter in forum C++ Programming
    Replies: 15
    Last Post: 08-27-2004, 06:43 AM