View Single Post
  #13 (permalink)  
Old October 6th, 2004, 01:28 PM
kokon kokon is offline
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