This program reads the above Bayes net from file,
  and then generates random cases that follow the
  probability distribution it specifies:
/* 
 *  SmulateCases.c
 *
 *  Example use of Netica-C-API for generating random cases that follow
 *  the probability distribution given by a Bayes net.
 */
#include "Netica.h"
#include "NeticaEx.c"

#define CHKERR  {if (GetError_ns (env, ERROR_ERR, NULL))  goto error;}

environ_ns* env;

int main (void){
	net_bn *orig_net;
	const nodelist_bn* orig_nodes;
	const int numcases = 200;
	stream_ns* casefile;
	char mesg[MESG_LEN_ns];
	int nn, res;
	
	env = NewNeticaEnviron_ns (NULL, NULL, NULL);
	res = InitNetica2_bn (env, mesg);
	printf ("%s\n", mesg);
	if (res < 0)  exit (-1);
	
	// Read in the net created by the BuildNet.c example program
	orig_net = ReadNet_bn ( NewStreamFile_ns ("AsiaEx.dne", env, NULL),
                                NO_VISUAL_INFO);
	orig_nodes = GetNetNodes_bn (orig_net);
	SetNetAutoUpdate_bn (orig_net, 0);
	CHKERR

	remove ("temp.cases");
	casefile =  NewStreamFile_ns ("AsiaEx.cas", env, NULL);
	for (nn = 0;  nn < numcases;  ++nn){
		RetractNetFindings_bn (orig_net);
		res= GenerateRandomCase_bn (orig_nodes, 0, 20);
		if (res >= 0)
			WriteCase_bn (orig_nodes, casefile, nn, -1);
		CHKERR
	}
	
end:
	FreeNet_bn (orig_net);
	res= CloseNetica_bn (env, mesg);
	printf ("%s\n", mesg);
	return (res < 0 ? -1 : 0);

error:
	fprintf (stderr, "SimulateCases: Error in %s\n", 
	         ErrorMessage_ns (GetError_ns (env, ERROR_ERR, NULL)));
	goto end;
}
  After this program runs, the file "AsiaEx.cas" contains:
IDnum  VisitAsia  Tuberculosis  Smoking    Cancer  TbOrCa  XRay
0      no_visit   absent	nonsmoker  absent  false   normal
1      no_visit   absent	smoker     absent  false   normal
2      no_visit   absent	smoker     absent  false   normal
3      no_visit   absent	nonsmoker  absent  false   normal
4      visit	  absent	nonsmoker  absent  false   normal
                          . . . 
198    no_visit   absent	nonsmoker  absent  false   normal
199    no_visit   absent	smoker     absent  false   normal