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
  #11 (permalink)  
Old September 13th, 2004, 09:40 AM
Authorized User
 
Join Date: Aug 2004
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Spivonious
Default

Mehdi, the poster wanted to simulate a real life coin toss with a coin that lands on heads 1/3 of the time and tails 2/3 of the time, not display the possible permutations of a certain number of tosses.

Reply With Quote
  #12 (permalink)  
Old September 14th, 2004, 01:19 PM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hello Spivonious,
using combinations give you all the possible answers
(I just wanted to have all the possible answers so I used combinations)

--------------------------------------------
Mehdi.:)
Reply With Quote
  #13 (permalink)  
Old October 6th, 2004, 01:28 PM
Registered User
 
Join Date: Oct 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It shouldn't be that difficult, I think.
Just create all the sequences first, eg:

#define N (10)
nh = N * 3 / 10;
np = N - nh;
char coins[N];
for (int i = 0;i < N;i++)
  (i < nh) ? coins[i] = 'h' : coins[i] = 't';

Then swap randomly:
#define MAXSWAP 10
for (int i = 0;i < MAXSWAP;i++)
{
  int top = <randomvalue>;
  int bot = <randomvalue>;
  swap(coins[top], coins[bot]);
}

Hope it does the trick.

KOkon.


Reply With Quote
  #14 (permalink)  
Old October 6th, 2004, 03:30 PM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hello,
this algorithm you told is easy but if I were you I would prefer using
Combinations instead of working on random values,
Combinations can assure us we have all the possible answers correctly.


--------------------------------------------
Mehdi.:)
Reply With Quote





Similar Threads
Thread Thread Starter Forum Replies Last Post
sequences Chacko C++ Programming 2 January 29th, 2007 08:27 AM
Does MS-Access 2003 support Sequences ramuis78 Access 0 July 5th, 2006 10:51 AM
Escape sequences for HTML olambe BOOK: ASP.NET Website Programming Problem-Design-Solution 2 July 28th, 2004 08:54 AM
Creating Editor narenkpattanaik General .NET 0 June 21st, 2004 11:44 PM
record sequences isheikh SQL Server 2000 2 April 9th, 2004 01:16 PM





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