Sponsored Content
Top Forums Programming How to set constrain on random numbers in c Post 302157473 by vikashtulsiyan on Friday 11th of January 2008 03:46:01 AM
Old 01-11-2008
Quote:
Originally Posted by Perderabo
If you had, say, 100, to distribute 5 into 5 variables: You pick a number from 1 to 100, let's say you get 20. The first variable gets the 20. Now 100 - 20 = 80 is left. So pick a number between 1 and 80. You stop when you get to only 1 variable and it gets the remainder. Or if the amount left reaches zero, you stop early and the rest of the variable must be zero.
jason Perderabo idea is cool. but if u want ot " distribute piece of cake evenly" then you can write an additional code

n=1+rand()%4
switch(n)
{
case 1:
// use perderabo idea starting with die1 - die4

case 2:

// use perderabo idea starting with die2 - die4,die1 in circular way

case 3:
//and so on...........
}

i know its not a very pretty solution but considering your unique constraints this is the best solution i got
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Random numbers without repetition

Is anyone know some scripts to generate random number without repetition using bash; for example generate 10 different random numbers. Thanks (8 Replies)
Discussion started by: asal_email
8 Replies

2. Shell Programming and Scripting

Random numbers from 0 to 1000

Hello All, I want to make a simple script which generate random number from 0 to 1000. and simply display it. Plz HELP!!!!!! Regards, Waqas Ahmed (2 Replies)
Discussion started by: wakhan
2 Replies

3. UNIX for Dummies Questions & Answers

seperating records with numbers from a set of numbers

I have two files one (numbers file)contains the numbers(approximately 30000) and the other file(record file) contains the records(approximately 40000)which may or may not contain the numbers from that file. I want to seperate the records which has the field 1=(any of the number from numbers... (15 Replies)
Discussion started by: Shiv@jad
15 Replies

4. Shell Programming and Scripting

Random Numbers - Perl

Hi Guys I have a script to find Ranomd numbers. But I want to make the file to produce more random. Could u guys help me plz. In this Script I have the code that generates random in for loop and the range I have specified in my %chromlength input and out put will be like this chrno start end... (3 Replies)
Discussion started by: repinementer
3 Replies

5. Shell Programming and Scripting

Generating random numbers

Hi, I am having trouble with generating random numbers. can this be done with awk? So I have a file that looks like this: 23 30 24 40 26 34 So column1 is start and column2 is end. I want to generate 3 random #'s between start and stop: So the output will look like this: ... (9 Replies)
Discussion started by: phil_heath
9 Replies

6. Programming

Random numbers in parent/child?

Hi I'm trying to generate random numbers both in parent process and the child process. But I get the same random number in both processes. Why doesn't it generate different numbers altough I seed random number generator? Here's my code: #include <stdio.h> #include <unistd.h> #include... (2 Replies)
Discussion started by: xyzt
2 Replies

7. Shell Programming and Scripting

unique random numbers awk

Hi, I have a small piece of awk code (see below) that generates random numbers. gawk -F"," 'BEGIN { srand(); for (i = 1; i <= 30; i++) printf("%s AM329_%04d\n",$0,int(36 * rand())+1) }' OFS=, AM329_hole_names.csv The code works fine and generates alphanumeric numbers like AM329_0001,... (2 Replies)
Discussion started by: theflamingmoe
2 Replies

8. Shell Programming and Scripting

Generate random numbers in script

i want to generate a random number through a script, and even if anyone reads the script, they wont be able to figure out what the random number is. only the person who setup the script would know it. something like this could work: random the full thread is here: ... (13 Replies)
Discussion started by: SkySmart
13 Replies

9. Homework & Coursework Questions

Random numbers

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! Write a shell script that will take the sum of two random number? Ex: Random n1 +Random n2 = result i tries to write it but i had some dufficulties ... (3 Replies)
Discussion started by: renegade755
3 Replies
DWARF_NEW_DIE(3)					   BSD Library Functions Manual 					  DWARF_NEW_DIE(3)

NAME
dwarf_new_die -- allocate a new debugging information entry LIBRARY
DWARF Access Library (libdwarf, -ldwarf) SYNOPSIS
#include <libdwarf.h> Dwarf_P_Die dwarf_new_die(Dwarf_P_Debug dbg, Dwarf_Tag tag, Dwarf_P_Die parent, Dwarf_P_Die child, Dwarf_P_Die left, Dwarf_P_Die right, Dwarf_Error *err); DESCRIPTION
Function dwarf_new_die() allocates a new DWARF debugging information entry and links it to another debugging information entry. Argument dbg should reference a DWARF producer instance allocated using dwarf_producer_init(3) or dwarf_producer_init_b(3). Argument tag should specify the tag of the newly created debugging information entry. Valid values for this argument are those for the DW_TAG_* symbols defined in <libdwarf.h>. Argument parent specifies the parent link of the debugging information entry. Argument child specifies the first child link of the debugging information entry. Argument left specifies the left sibling link of the debugging information entry. Argument right specifies the right sibling link of the debugging information entry. Only one of arguments parent, child, left and right is allowed to be non-NULL. Application code can subsequently call the function dwarf_die_link(3) to change the links for the created debugging information entry. If argument err is not NULL, it will be used to store error information in case of an error. RETURN VALUES
On success, function dwarf_new_die() returns the newly created debugging information entry. In case of an error, function dwarf_new_die() returns DW_DLV_BADADDR and sets the argument err. ERRORS
Function dwarf_new_die() can fail with: [DW_DLE_ARGUMENT] Argument dbg was NULL. [DW_DLE_ARGUMENT] More than one of the arguments parent, child, left and right were non-NULL. [DW_DLE_MEMORY] An out of memory condition was encountered during the execution of the function. EXAMPLES
To create debugging information entries and add them to the producer instance, use: Dwarf_P_Debug dbg; Dwarf_P_Die die1, die2; Dwarf_Error de; /* ... assume dbg refers to a DWARF producer instance ... */ die1 = dwarf_new_die(dbg, DW_TAG_compilation_unit, NULL, NULL, NULL, NULL, &de); if (die1 == NULL) { warnx("dwarf_new_die failed: %s", dwarf_errmsg(-1)); return; } die2 = dwarf_new_die(dbg, DW_TAG_base_type, die1, NULL, NULL, NULL, &de); if (die1 == NULL) { warnx("dwarf_new_die failed: %s", dwarf_errmsg(-1)); return; } if (dwarf_add_die_to_debug(dbg, die1, &de) != DW_DLV_OK) { warnx("dwarf_add_die_to_debug failed: %s", dwarf_errmsg(-1)); return; } SEE ALSO
dwarf(3), dwarf_add_die_to_debug(3), dwarf_die_link(3), dwarf_producer_init(3), dwarf_producer_init_b(3) BSD
September 4, 2011 BSD
All times are GMT -4. The time now is 11:26 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy