예제 #1
0
static gboolean set_new_position(gpointer pipeline)
{
    gint64 seek_pos = 0;
    GRand* rand_generator = g_rand_new();

    g_debug("Starting seek :-)");
    if(counter >= SEEK_COUNT){
        g_rand_free (rand_generator);
        return FALSE;
    }
    counter++;
    if(volta_inicio){
        seek_pos = 0;
        volta_inicio = FALSE;
    }else{
        seek_pos = GST_SECOND * g_rand_int_range(rand_generator, 1, 30);
        volta_inicio = TRUE;
    }
     
    if(!gst_element_seek_simple(pipeline, GST_FORMAT_TIME, 
                                    GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_KEY_UNIT, 
                                    seek_pos)){
        g_debug("Error seeking!");
        g_rand_free (rand_generator);
        return TRUE;
    }
    
    g_debug("Seeked with success :-), position set is[%lld]", seek_pos / GST_SECOND);
    g_rand_free (rand_generator);
    return TRUE;
}
예제 #2
0
파일: until.c 프로젝트: kroody/codesnippet
int	main(int argc, char *argv[])
{
	GRand *rand;
	GTimer *timer;
	
	gint n;
	gint i, j;
	gint x = 0;
	rand = g_rand_new();	//创建随机数对象
	for(n=0; n<20; n++)
	{	//产生随机数并显示出来
		g_print("%d\t",g_rand_int_range(rand,1,100));
	}
	g_print("\n");
	g_rand_free(rand);	//释放随机数对象
	//创建计时器
	timer = g_timer_new();
	g_timer_start(timer);//开始计时
	for(i=0; i<10000; i++)
		for(j=0; j<3000; j++)
			x++;//累计
	g_timer_stop(timer);//计时结束
	//输出计时结果
	g_print("%ld\tall:%.2f seconds was used!\n",x,g_timer_elapsed(timer,NULL));
}
void
_odccm_connection_broker_take_connection (OdccmConnectionBroker *self,
                                          GConn *conn)
{
  OdccmConnectionBrokerPrivate *priv = ODCCM_CONNECTION_BROKER_GET_PRIVATE (self);
  GRand *rnd;
  GIOChannel *chan;
  guint uid;

  g_assert (priv->conn == NULL);

  priv->conn = conn;

  rnd = g_rand_new ();
  priv->filename = g_strdup_printf ("/tmp/odccm-%08x%08x%08x%08x.sock",
      g_rand_int (rnd), g_rand_int (rnd), g_rand_int (rnd), g_rand_int (rnd));
  g_rand_free (rnd);

  priv->server = gnet_unix_socket_server_new (priv->filename);

  _odccm_get_dbus_sender_uid (dbus_g_method_get_sender (priv->ctx), &uid);

  chmod (priv->filename, S_IRUSR | S_IWUSR);
  chown (priv->filename, uid, -1);

  chan = gnet_unix_socket_get_io_channel (priv->server);
  g_io_add_watch (chan, G_IO_IN, server_socket_readable_cb, self);

  dbus_g_method_return (priv->ctx, priv->filename);
  priv->ctx = NULL;
}
예제 #4
0
const guint8* 
token_key_new ( Algorithm algorithm, guint *length )
{
  const guint8 *key;
  GRand *rng;
  guint32 *buf;
  guint i, il=0;

  rng = g_rand_new ();

  switch ( algorithm )
    {
    case HOTP: il = DEFAULT_HOTP_KEY_LENGTH / 32; break;
    case MOTP: il = DEFAULT_MOTP_KEY_LENGTH / 32; break;
    default:;
    }

  buf = g_malloc ( il * 32 );
  for ( i=0; i < il ; ++ i )
    buf[i] = g_rand_int ( rng );

  key = (guint8*)buf;
  *length = il * 4; // 4 guint8's per guint32

  g_rand_free ( rng );

  return key;
}
예제 #5
0
void
test_surface_set(void)
{
    enum { max_size = 255, niter = 40 };

    GRand *rng = g_rand_new_with_seed(42);

    for (guint iter = 0; iter < niter; iter++) {
        guint res = g_rand_int_range(rng, 1, max_size);
        GwySurface *surface = gwy_surface_new_sized(res);

        for (guint i = 0; i < res; i++) {
            GwyXYZ pt = { i, G_PI/(i + 1), -0.5*i*i };
            gwy_surface_set(surface, i, pt);
        }

        for (guint k = 0; k < res; k++) {
            GwyXYZ pt = gwy_surface_get(surface, k);
            g_assert_cmpfloat(pt.x, ==, k);
            g_assert_cmpfloat(pt.y, ==, G_PI/(k + 1));
            g_assert_cmpfloat(pt.z, ==, -0.5*k*k);
        }
        g_object_unref(surface);
    }

    g_rand_free(rng);
}
예제 #6
0
void
test_field_surface_area_planar(void)
{
    enum { max_size = 76 };
    GRand *rng = g_rand_new_with_seed(42);
    gsize niter = 50;

    for (guint iter = 0; iter < niter; iter++) {
        guint xres = g_rand_int_range(rng, 1, max_size);
        guint yres = g_rand_int_range(rng, 1, max_size);
        gdouble alpha = g_rand_double_range(rng, -5.0, 5.0);
        gdouble beta = g_rand_double_range(rng, -5.0, 5.0);
        GwyField *field = field_make_planar(xres, yres, alpha, beta);
        gdouble area, area_expected;
        gwy_field_set_xreal(field, xres/sqrt(xres*yres));
        gwy_field_set_yreal(field, yres/sqrt(xres*yres));
        area = gwy_field_surface_area(field, NULL, NULL, GWY_MASK_IGNORE);
        area_expected = planar_field_surface_area(field);
        g_assert_cmpfloat(fabs(area - area_expected)/area_expected, <=, 1e-9);

        gwy_field_set_xreal(field, 1.0);
        gwy_field_set_yreal(field, 1.0);
        area = gwy_field_surface_area(field, NULL, NULL, GWY_MASK_IGNORE);
        area_expected = planar_field_surface_area(field);
        g_assert_cmpfloat(fabs(area - area_expected)/area_expected, <=, 1e-9);

        g_object_unref(field);
    }
    g_rand_free(rng);
}
예제 #7
0
void
test_field_process_quarters_unmasked_border(void)
{
    enum { max_size = 15, niter = 100 };
    gdouble eps = 1e-12;
    GRand *rng = g_rand_new_with_seed(42);

    for (guint iter = 0; iter < niter; iter++) {
        guint xres = g_rand_int_range(rng, 1, max_size);
        guint yres = g_rand_int_range(rng, 1, max_size);
        guint width = g_rand_int_range(rng, 1, xres+1);
        guint height = g_rand_int_range(rng, 1, yres+1);
        guint col = g_rand_int_range(rng, 0, xres-width+1);
        guint row = g_rand_int_range(rng, 0, yres-height+1);
        GwyFieldPart fpart = { col, row, width, height };
        GwyField *field = gwy_field_new_sized(xres, yres, FALSE);
        gboolean useallfunc = g_rand_boolean(rng);
        field_randomize(field, rng);
        gdouble result = 0.0;
        gwy_field_process_quarters(field, &fpart, NULL, 0, TRUE,
                                   sum_quarters,
                                   useallfunc ? sum_allquarters : NULL,
                                   &result);
        gdouble reference = 0.0;
        for (guint i = 0; i < height; i++) {
            for (guint j = 0; j < width; j++) {
                reference += 4.0*gwy_field_index(field, col + j, row + i);
            }
        }
        gwy_assert_floatval(result, reference, eps);

        g_object_unref(field);
    }
    g_rand_free(rng);
}
예제 #8
0
void
test_field_volume_voids_planar(void)
{
    enum { max_size = 66 };
    GRand *rng = g_rand_new_with_seed(42);
    gsize niter = 100;

    for (guint iter = 0; iter < niter; iter++) {
        guint xres = g_rand_int_range(rng, 3, max_size);
        guint yres = g_rand_int_range(rng, 3, max_size);
        gdouble alpha = g_rand_double_range(rng, -5.0, 5.0);
        gdouble beta = g_rand_double_range(rng, -5.0, 5.0);
        gdouble base = g_rand_double_range(rng, -5.0, 5.0);
        GwyField *field = field_make_planar(xres, yres, alpha, beta);
        GwyFieldPart fpart = { 1, 1, xres-2, yres-2 };
        gdouble volume, volume_expected;
        gwy_field_set_xreal(field, xres/sqrt(xres*yres));
        gwy_field_set_yreal(field, yres/sqrt(xres*yres));
        volume = gwy_field_material_volume(field, &fpart,
                                           NULL, GWY_MASK_IGNORE, FALSE, base);
        volume_expected = planar_field_material_volume(field, base, FALSE);
        gwy_assert_floatval(volume, volume_expected, 1e-9*fabs(volume_expected));

        gwy_field_set_xreal(field, 1.0);
        gwy_field_set_yreal(field, 1.0);
        volume_expected = planar_field_material_volume(field, base, FALSE);
        volume = gwy_field_material_volume(field, &fpart,
                                           NULL, GWY_MASK_IGNORE, FALSE, base);
        gwy_assert_floatval(volume, volume_expected, 1e-9*fabs(volume_expected));

        g_object_unref(field);
    }
    g_rand_free(rng);
}
예제 #9
0
static void _random2_distribution (GPtrArray *points,
				  AranSolver2d *solver)
{
  guint i;
  PointAccum *point;
  GRand *rand = g_rand_new_with_seed (_random_seed);

  point = point_accum_alloc (TRUE, NULL);

  for (i=0; i<np; i++)
    {

#ifdef VSG_HAVE_MPI
      if (i%_flush_interval == 0)
        {
          aran_solver2d_migrate_flush (solver);
          if (i%(_flush_interval*10) == 0)
            {
              if (_verbose && rk == 0)
                g_printerr ("%d: contiguous dist before %dth point\n", rk, i);

              aran_solver2d_distribute_contiguous_leaves (solver);
            }
        }
#endif /* VSG_HAVE_MPI */

      point->vector.x = g_rand_double_range (rand, -R, R);;
      point->vector.y = g_rand_double_range (rand, -R, R);;
      point->density = 1.;
      point->accum = 0.;
      point->id = i;

      if (check) memcpy (&check_points[i], point, sizeof (PointAccum));

      if (aran_solver2d_insert_point_local (solver, point))
        {
          if (i % 10000 == 0 && _verbose)
            g_printerr ("%d: insert %dth point\n", rk, i);

          point = point_accum_alloc (TRUE, NULL);
        }

#ifdef VSG_HAVE_MPI
      if (i%(_flush_interval*10) == 0)
        {
          if (_verbose && rk == 0)
            g_printerr ("%d: contiguous dist before %dth point\n", rk, i);
          aran_solver2d_distribute_contiguous_leaves (solver);
        }
#endif /* VSG_HAVE_MPI */
    }

  point_accum_destroy (point, TRUE, NULL);

#ifdef VSG_HAVE_MPI
  aran_solver2d_distribute_contiguous_leaves (solver);
#endif /* VSG_HAVE_MPI */

  g_rand_free (rand);
}
예제 #10
0
/**
 * @brief Randomizes the order of the hosts objects in the collection.
 * Not to be used while iterating over the single hosts as it resets the
 * iterator.
 *
 * @param[in] hosts The hosts collection to shuffle.
 */
void
openvas_hosts_shuffle (openvas_hosts_t *hosts)
{
  int count;
  GList *new_list;
  GRand *rand;

  if (hosts == NULL)
    return;

  count = openvas_hosts_count (hosts);
  new_list = NULL;

  rand = g_rand_new ();

  while (count)
    {
      GList *element;

      /* Get element from random position [0, count[. */
      element = g_list_nth (hosts->hosts, g_rand_int_range (rand, 0, count));
      /* Remove it. */
      hosts->hosts = g_list_remove_link (hosts->hosts, element);
      /* Insert it in new list */
      new_list = g_list_concat (element, new_list);
      count--;
    }
  hosts->hosts = new_list;
  hosts->current = hosts->hosts;

  g_rand_free (rand);
}
예제 #11
0
/*  Simple AI:

	1. If AI can win with the following move, make it.
	2. If human can win with the following move, block it.
	3. Otherwise, random spot.
*/
void gb_logic()
{
	int i;
	if( gb_get_spaces() > 0)
	{
		i = gb_table_check('o');
		if( i >= 0)
			gb_add_mark(i, 'o');
		else
		{
			i = gb_table_check('x');
			if(i >= 0)
				gb_add_mark(i, 'o');
			else
			{
				gboolean done = FALSE;
				GRand *r = g_rand_new();
				while(!done)
				{
					i = g_rand_int(r)%9;
					if( mark[i] == 'k')
					{
						gb_add_mark(i, 'o');
						done = TRUE;
					}
				}
				g_rand_free(r);
			}
		}
	}
}
예제 #12
0
파일: ft.c 프로젝트: Formenel/mrim-prpl
void mrim_xfer_send_rq(PurpleXfer *xfer) {
	gchar *file_name = purple_xfer_get_local_filename(xfer);
	purple_debug_info("mrim-prpl", "[%s] Sending file '%s'\n", __func__, file_name);
	MrimFT *mrim_ft = xfer->data;
	mrim_ft->xfer = xfer;
	mrim_ft->count = 1;
	mrim_ft->files = g_new0(MrimFT, 1);
	mrim_ft->files[0].name = basename(file_name); // TODO: strdup???
	{
		GRand *rnd = g_rand_new();
		mrim_ft->id = g_rand_int(rnd);
		g_rand_free(rnd);
	}
	{
		struct stat st;
		stat(file_name, &st);
		mrim_ft->files[0].size = st.st_size;
	}
	MrimData *mrim = mrim_ft->mrim;
	MrimPackage *pack = mrim_package_new(mrim->seq++, MRIM_CS_FILE_TRANSFER);
	mrim_package_add_LPSA(pack, mrim_ft->user_name);
	mrim_package_add_UL(pack, mrim_ft->id);
	mrim_package_add_UL(pack, mrim_ft->files[0].size);
	gchar *file_list = g_strdup_printf("%s;%u;", mrim_ft->files[0].name, mrim_ft->files[0].size);
	gchar *my_ip = "1.2.3.4:1234;"; // Заведомо некорректное значение, чтобы клиент обломался и пошёл использовать зеркальный прокси TODO
	mrim_package_add_UL(pack, 4 + strlen(file_list) + 4 + 4 + strlen(my_ip));
	mrim_package_add_LPSA(pack, file_list);
	mrim_package_add_UL(pack, 0);
	mrim_package_add_LPSA(pack, my_ip);
	//mrim_add_ack_cb(mrim, pack->header->seq, mrim_xfer_ack, xfer);
	g_hash_table_insert(mrim->transfers, GUINT_TO_POINTER(mrim_ft->id), xfer);
	mrim_package_send(pack, mrim);
}
예제 #13
0
static void
gimp_operation_dissolve_mode_class_init (GimpOperationDissolveModeClass *klass)
{
  GeglOperationClass               *operation_class;
  GeglOperationPointComposer3Class *point_composer_class;
  GRand                            *gr;
  gint                              i;

  operation_class      = GEGL_OPERATION_CLASS (klass);
  point_composer_class = GEGL_OPERATION_POINT_COMPOSER3_CLASS (klass);

  gegl_operation_class_set_keys (operation_class,
                                 "name",        "gimp:dissolve-mode",
                                 "description", "GIMP dissolve mode operation",
                                 "categories",  "compositors",
                                 NULL);

  operation_class->prepare      = gimp_operation_dissolve_mode_prepare;
  point_composer_class->process = gimp_operation_dissolve_mode_process;

  /* generate a table of random seeds */
  gr = g_rand_new_with_seed (314159265);
  for (i = 0; i < RANDOM_TABLE_SIZE; i++)
    random_table[i] = g_rand_int (gr);

  g_rand_free (gr);
}
예제 #14
0
static gboolean
gimp_operation_dissolve_mode_process (GeglOperation       *operation,
                                      void                *in_buf,
                                      void                *aux_buf,
                                      void                *aux2_buf,
                                      void                *out_buf,
                                      glong                samples,
                                      const GeglRectangle *result,
                                      gint                 level)
{
  gdouble         opacity  = GIMP_OPERATION_POINT_LAYER_MODE (operation)->opacity;
  gfloat         *in       = in_buf;
  gfloat         *out      = out_buf;
  gfloat         *aux      = aux_buf;
  gfloat         *mask     = aux2_buf;
  const gboolean  has_mask = mask != NULL;
  gint            x, y;

  for (y = result->y; y < result->y + result->height; y++)
    {
      GRand *gr = g_rand_new_with_seed (random_table[y % RANDOM_TABLE_SIZE]);

      /* fast forward through the rows pseudo random sequence */
      for (x = 0; x < result->x; x++)
        g_rand_int (gr);

      for (x = result->x; x < result->x + result->width; x++)
        {
          gfloat value = aux[ALPHA] * opacity * 255;

          if (has_mask)
            value *= *mask;

          if (g_rand_int_range (gr, 0, 255) >= value)
            {
              out[0] = in[0];
              out[1] = in[1];
              out[2] = in[2];
              out[3] = in[3];
            }
          else
            {
              out[0] = aux[0];
              out[1] = aux[1];
              out[2] = aux[2];
              out[3] = 1.0;
            }

          in   += 4;
          out  += 4;
          aux  += 4;

          if (has_mask)
            mask ++;
        }
      g_rand_free (gr);
    }

  return TRUE;
}
예제 #15
0
static void
about_dialog_reshuffle (GimpAboutDialog *dialog)
{
  GRand *gr = g_rand_new ();
  gint   i;

  for (i = 0; i < dialog->n_authors; i++)
    dialog->shuffle[i] = i;

  for (i = START_INDEX; i < dialog->n_authors; i++)
    {
      gint j = g_rand_int_range (gr, START_INDEX, dialog->n_authors);

      if (i != j)
        {
          gint t;

          t = dialog->shuffle[j];
          dialog->shuffle[j] = dialog->shuffle[i];
          dialog->shuffle[i] = t;
        }
    }

  g_rand_free (gr);
}
예제 #16
0
void
test_int_set_assign(void)
{
    GRand *rng = g_rand_new_with_seed(42);
    gsize niter = 20;

    for (guint iter = 0; iter < niter; iter++) {
        GwyIntSet *original = gwy_int_set_new(), *copy = gwy_int_set_new();
        int_set_randomize(original, rng);

        guint counter = 0, xcounter = 0;
        g_signal_connect_swapped(copy, "assigned",
                                 G_CALLBACK(record_signal), &counter);
        g_signal_connect_swapped(copy, "added",
                                 G_CALLBACK(record_signal), &xcounter);
        g_signal_connect_swapped(copy, "removed",
                                 G_CALLBACK(record_signal), &xcounter);
        g_signal_connect_swapped(original, "added",
                                 G_CALLBACK(record_signal), &xcounter);
        g_signal_connect_swapped(original, "removed",
                                 G_CALLBACK(record_signal), &xcounter);
        g_signal_connect_swapped(original, "assigned",
                                 G_CALLBACK(record_signal), &xcounter);
        gwy_int_set_assign(copy, original);
        int_set_assert_order(copy);
        int_set_assert_equal(copy, original);
        g_assert_cmpuint(counter, ==, 1);
        g_assert_cmpuint(xcounter, ==, 0);

        g_object_unref(copy);
        g_object_unref(original);
    }
    g_rand_free(rng);
}
예제 #17
0
static void
about_dialog_reshuffle (GimpAboutDialog *dialog)
{
  GRand *gr = g_rand_new ();
  gint   i;

  for (i = 0; i < dialog->n_authors; i++)
    dialog->shuffle[i] = i;

  /* here we rely on the authors array having Peter and Spencer first */
#define START_INDEX 2

  for (i = START_INDEX; i < dialog->n_authors; i++)
    {
      gint j = g_rand_int_range (gr, START_INDEX, dialog->n_authors);

      if (i != j)
        {
          gint t;

          t = dialog->shuffle[j];
          dialog->shuffle[j] = dialog->shuffle[i];
          dialog->shuffle[i] = t;
        }
    }

#undef START_INDEX

  g_rand_free (gr);
}
예제 #18
0
gchar *
fb_util_rand_alnum(guint len)
{
    gchar *ret;
    GRand *rand;
    guint i;
    guint j;

    static const gchar chars[] =
        "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
        "abcdefghijklmnopqrstuvwxyz"
        "0123456789";
    static const gsize charc = G_N_ELEMENTS(chars) - 1;

    g_return_val_if_fail(len > 0, NULL);
    rand = g_rand_new();
    ret = g_new(gchar, len + 1);

    for (i = 0; i < len; i++) {
        j = g_rand_int_range(rand, 0, charc);
        ret[i] = chars[j];
    }

    ret[len] = 0;
    g_rand_free(rand);
    return ret;
}
예제 #19
0
파일: test-server.c 프로젝트: IMCG/kiro
int 
main (void)
{
    KiroServer *server = kiro_server_new ();
    KiroTrb *rb = kiro_trb_new ();
    kiro_trb_reshape (rb, 512 * 512, 15);
    GRand *rand = g_rand_new();

    if (0 > kiro_server_start (server, NULL, "60010", kiro_trb_get_raw_buffer (rb), kiro_trb_get_raw_size (rb))) {
        g_critical ("Failed to start server properly");
        goto done;
    }

    guint frame = 0;
    gchar *buffer = NULL;

    while (1) {
        sleep (1);
        buffer = kiro_trb_dma_push (rb);
        print_current_frame (buffer, frame, 512, 512, rand);
        frame++;
        if (frame % 1000 == 0)
            kiro_server_realloc (server, kiro_trb_get_raw_buffer (rb), kiro_trb_get_raw_size (rb));
    }

done:
    g_rand_free (rand);
    kiro_trb_free (rb);
    kiro_server_free (server);
    return 0;
}
예제 #20
0
파일: druxlord.c 프로젝트: ajhwb/druxlord
void
generate_drug ()
{
    GRand *rand;
    gint i, j, divisor;

    rand = g_rand_new ();

    for (i = 0; i < DRUG_NUM; i++)
        for (j = 0; j < CITY_NUM; j++)
        {
            drug_table[i][j].available = g_rand_boolean (rand);
            if (drug_table[i][j].available)
            {
                drug_table[i][j].qty = g_rand_int_range (rand, 0, 10);
                if (drug_table[i][j].qty > 0)
                    divisor = drug_table[i][j].qty;
                else
                    divisor = g_rand_int_range (rand, 1, 10);
                drug_table[i][j].price = ((double) 10 / divisor) *
                                         g_rand_double_range (rand, 0.1, 1.0) *
                                         drug_price[i];
            }
        }

    g_rand_free (rand);
}
static GByteArray *
generate_duid_from_machine_id (void)
{
	GByteArray *duid;
	char *contents = NULL;
	GChecksum *sum;
	guint8 buffer[32]; /* SHA256 digest size */
	gsize sumlen = sizeof (buffer);
	const guint16 duid_type = g_htons (4);
	uuid_t uuid;
	GRand *generator;
	guint i;
	gboolean success = FALSE;

	/* Get the machine ID from /etc/machine-id; it's always in /etc no matter
	 * where our configured SYSCONFDIR is.  Alternatively, it might be in
	 * LOCALSTATEDIR /lib/dbus/machine-id.
	 */
	if (   g_file_get_contents ("/etc/machine-id", &contents, NULL, NULL)
	    || g_file_get_contents (LOCALSTATEDIR "/lib/dbus/machine-id", &contents, NULL, NULL)) {
		contents = g_strstrip (contents);
		success = machine_id_parse (contents, uuid);
		if (success) {
			/* Hash the machine ID so it's not leaked to the network */
			sum = g_checksum_new (G_CHECKSUM_SHA256);
			g_checksum_update (sum, (const guchar *) &uuid, sizeof (uuid));
			g_checksum_get_digest (sum, buffer, &sumlen);
			g_checksum_free (sum);
		}
		g_free (contents);
	}

	if (!success) {
		nm_log_warn (LOGD_DHCP6, "Failed to read " SYSCONFDIR "/machine-id "
		             "or " LOCALSTATEDIR "/lib/dbus/machine-id to generate "
		             "DHCPv6 DUID; creating non-persistent random DUID.");

		generator = g_rand_new ();
		for (i = 0; i < sizeof (buffer) / sizeof (guint32); i++)
			((guint32 *) buffer)[i] = g_rand_int (generator);
		g_rand_free (generator);
	}

	/* Generate a DHCP Unique Identifier for DHCPv6 using the
	 * DUID-UUID method (see RFC 6355 section 4).  Format is:
	 *
	 * u16: type (DUID-UUID = 4)
	 * u8[16]: UUID bytes
	 */
	duid = g_byte_array_sized_new (18);
	g_byte_array_append (duid, (guint8 *) &duid_type, sizeof (duid_type));

	/* Since SHA256 is 256 bits, but UUID is 128 bits, we just take the first
	 * 128 bits of the SHA256 as the DUID-UUID.
	 */
	g_byte_array_append (duid, buffer, 16);

	return duid;
}
예제 #22
0
static void _random2_fill (AranSolver3d *solver)
{
  guint64 i;
  PointAccum *point;
  GRand *rand = g_rand_new_with_seed (_random_seed);

  point = point_accum_alloc (TRUE, NULL);

  for (i=0; i<np; i++)
    {

#ifdef VSG_HAVE_MPI
      if (i%_flush_interval == 0)
        {
          aran_solver3d_migrate_flush (solver);
          if (i%(_flush_interval*10) == 0)
            {
              if (_verbose && rk == 0)
                g_printerr ("%d: contiguous dist before %luth point\n", rk, i);

              aran_solver3d_distribute_contiguous_leaves (solver);
              _flush_interval *=2;
            }
        }
#endif /* VSG_HAVE_MPI */

      point->vector.x = g_rand_double_range (rand, -R, R);;
      point->vector.y = g_rand_double_range (rand, -R, R);;
      point->vector.z = g_rand_double_range (rand, -R, R);;
      point->density = 1./np;
      point->field = VSG_V3D_ZERO;
      point->id = i;

      /* if (i == 3) point->density = 0.; */
      /* if (i == 4) point->density = 0.; */
      /* if (i == 5) point->density = 0.; */

      if (check) memcpy (&check_points[i], point, sizeof (PointAccum));

      if (aran_solver3d_insert_point_local (solver, point))
        {
          if (i % 10000 == 0 && _verbose)
            g_printerr ("%d: insert %luth point\n", rk, i);

          point = point_accum_alloc (TRUE, NULL);
        }

    }

  point_accum_destroy (point, TRUE, NULL);

#ifdef VSG_HAVE_MPI
  aran_solver3d_migrate_flush (solver);
  aran_solver3d_distribute_contiguous_leaves (solver);
#endif /* VSG_HAVE_MPI */

  g_rand_free (rand);
}
예제 #23
0
void
teardown (void)
{
	g_object_unref (component);
	g_object_unref (factory);
	g_rand_free (rnd);

	return;
}
예제 #24
0
static void rt_pattern_free(rt_pattern* rtpat)
{
    if (!rtpat)
        return;

    g_rand_free(rtpat->rnd);
    free(rtpat->events);
    free(rtpat);
}
예제 #25
0
void gw_flashcardstore_trim (GwFlashCardStore *store, gint max)
{
    //Sanity Checks
    if (store == NULL) return;
    if (max < 1) return;

    //Declarations
    GtkTreeModel *model;
    GtkTreePath *path;
    GtkTreeIter iter;
    gboolean valid;
    gint children;
    gchar *path_string;
    GRand *random;
    gint position;

    gtk_tree_sortable_set_sort_column_id (
        GTK_TREE_SORTABLE (store), 
        GW_FLASHCARDSTORE_COLUMN_WEIGHT, 
        GTK_SORT_DESCENDING);

    model = GTK_TREE_MODEL (store);
    random = g_rand_new ();
    children = gtk_tree_model_iter_n_children (model, NULL);

    if (random != NULL)
    {
      while (children > max && children > 0)
      {
        position = g_rand_int_range (random, 0, children);
        path_string = g_strdup_printf ("%d", position);
        if (path_string != NULL)
        {
          valid = gtk_tree_model_get_iter_from_string (model, &iter, path_string);
          if (valid)
          {
            gtk_tree_model_get (model, &iter, GW_FLASHCARDSTORE_COLUMN_TREE_PATH, &path, -1);
            if (path != NULL) gtk_tree_path_free (path); path = NULL;
            gtk_list_store_remove (GTK_LIST_STORE (store), &iter);
          }
          g_free (path_string); path_string = NULL;
        }
        children--;
      }
      g_rand_free (random); random = NULL;
    } 

    gtk_tree_sortable_set_sort_column_id (
        GTK_TREE_SORTABLE (store), 
        GW_FLASHCARDSTORE_COLUMN_ORDER, 
        GTK_SORT_ASCENDING);
    gtk_tree_sortable_set_sort_column_id (
        GTK_TREE_SORTABLE (store), 
        GTK_TREE_SORTABLE_UNSORTED_SORT_COLUMN_ID, 
        GTK_SORT_ASCENDING);
}
예제 #26
0
static guchar*
rgb_to_hsl (GimpDrawable     *drawable,
            LICEffectChannel  effect_channel)
{
  guchar       *themap, data[4];
  gint          x, y;
  GimpRGB       color;
  GimpHSL       color_hsl;
  gdouble       val = 0.0;
  glong         maxc, index = 0;
  GimpPixelRgn  region;
  GRand        *gr;

  gr = g_rand_new ();

  maxc = drawable->width * drawable->height;

  gimp_pixel_rgn_init (&region, drawable, border_x, border_y,
                       border_w, border_h, FALSE, FALSE);

  themap = g_new (guchar, maxc);

  for (y = 0; y < region.h; y++)
    {
      for (x = 0; x < region.w; x++)
        {
          data[3] = 255;

          gimp_pixel_rgn_get_pixel (&region, data, x, y);
          gimp_rgba_set_uchar (&color, data[0], data[1], data[2], data[3]);
          gimp_rgb_to_hsl (&color, &color_hsl);

          switch (effect_channel)
            {
            case LIC_HUE:
              val = color_hsl.h * 255;
              break;
            case LIC_SATURATION:
              val = color_hsl.s * 255;
              break;
            case LIC_BRIGHTNESS:
              val = color_hsl.l * 255;
              break;
            }

          /* add some random to avoid unstructured areas. */
          val += g_rand_double_range (gr, -1.0, 1.0);

          themap[index++] = (guchar) CLAMP0255 (RINT (val));
        }
    }

  g_rand_free (gr);

  return themap;
}
예제 #27
0
static void
is_fake_plugin_finalize(GObject *object)
{
	IsFakePlugin *self = IS_FAKE_PLUGIN(object);
	IsFakePluginPrivate *priv = self->priv;

	g_rand_free(priv->rand);

	G_OBJECT_CLASS(is_fake_plugin_parent_class)->finalize(object);
}
예제 #28
0
gboolean
gimp_operation_dissolve_mode_process_pixels (gfloat              *in,
                                             gfloat              *aux,
                                             gfloat              *mask,
                                             gfloat              *out,
                                             gfloat               opacity,
                                             glong                samples,
                                             const GeglRectangle *result,
                                             gint                 level)
{
  const gboolean has_mask = mask != NULL;
  gint           x, y;

  for (y = result->y; y < result->y + result->height; y++)
    {
      GRand *gr = g_rand_new_with_seed (random_table[y % RANDOM_TABLE_SIZE]);

      /* fast forward through the rows pseudo random sequence */
      for (x = 0; x < result->x; x++)
        g_rand_int (gr);

      for (x = result->x; x < result->x + result->width; x++)
        {
          gfloat value = aux[ALPHA] * opacity * 255;

          if (has_mask)
            value *= *mask;

          if (g_rand_int_range (gr, 0, 255) >= value)
            {
              out[0] = in[0];
              out[1] = in[1];
              out[2] = in[2];
              out[3] = in[3];
            }
          else
            {
              out[0] = aux[0];
              out[1] = aux[1];
              out[2] = aux[2];
              out[3] = 1.0;
            }

          in   += 4;
          out  += 4;
          aux  += 4;

          if (has_mask)
            mask ++;
        }
      g_rand_free (gr);
    }

  return TRUE;
}
/* UV sphere fill */
static void _uvsphere_fill (AranSolver3d *solver)
{
  gint i;
  PointAccum *point;
  VsgVector3d lb, ub;
  GRand *rand = g_rand_new_with_seed (_random_seed);
  gdouble r;

  aran_solver3d_get_bounds (solver, &lb, &ub);
  r = MIN (lb.x, ub.x);

  point = point_accum_alloc (TRUE, NULL);

  for (i=0; i< np; i++)
    {
      gdouble theta, phi;

      theta = g_rand_double_range (rand, 0.01 * G_PI, 0.99 * G_PI);
      phi = g_rand_double_range (rand, 0., 2.*G_PI);

      vsg_vector3d_from_spherical (&point->vector, r, theta, phi);
      point->density = 1.;
      point->field = VSG_V3D_ZERO;
      point->id = i;

      if (check) memcpy (&check_points[i], point, sizeof (PointAccum));

      if (aran_solver3d_insert_point_local (solver, point))
        {
          if (i % 10000 == 0 && _verbose)
            g_printerr ("%d: insert %dth point\n", rk, i);

          point = point_accum_alloc (TRUE, NULL);
        }

#ifdef VSG_HAVE_MPI
      if (i%(_flush_interval*10) == 0)
        {
          if (_verbose && rk == 0)
            g_printerr ("%d: contiguous dist before %dth point\n", rk, i);
          aran_solver3d_distribute_contiguous_leaves (solver);

          _flush_interval *=2;
        }
#endif /* VSG_HAVE_MPI */
    }

  point_accum_destroy (point, TRUE, NULL);

#ifdef VSG_HAVE_MPI
  aran_solver3d_distribute_contiguous_leaves (solver);
#endif /* VSG_HAVE_MPI */

  g_rand_free (rand);
}
예제 #30
0
void
queue_finish(struct queue *queue)
{
	queue_clear(queue);

	g_free(queue->items);
	g_free(queue->order);
	g_free(queue->id_to_position);

	g_rand_free(queue->rand);
}