Ejemplo n.º 1
0
static void
_append_random_chars (gchar *d, const char *chars, guint n)
{
	GRand *r = oio_ext_local_prng ();
	size_t len = strlen (chars);
	gchar *p = d + strlen(d);
	for (guint i=0; i<n ;i++)
		*(p++) = chars [g_rand_int_range (r, 0, len)];
	*p = '\0';
}
Ejemplo n.º 2
0
void
oio_ext_array_shuffle (gpointer *array, gsize len)
{
	GRand *r = oio_ext_local_prng ();
	while (len-- > 1) {
		guint32 i = g_rand_int_range (r, 0, len+1);
		if (i == len)
			continue;
		gpointer tmp = array[i];
		array[i] = array[len];
		array[len] = tmp;
	}
}
Ejemplo n.º 3
0
static GSList*
gslist_merge_random (GSList *l1, GSList *l2)
{
	GSList *next, *result = NULL;
	GRand *r = oio_ext_local_prng ();
	while (l1 || l2) {
		if (l1 && l2) {
			if (g_rand_boolean(r))
				PREPEND(result,l1);
			else
				PREPEND(result,l2);
		}
		else {
			if (l1)
				PREPEND(result,l1);
			else
				PREPEND(result,l2);
		}
	}
	return result;
}