Search
 
SCRIPT & CODE EXAMPLE
 

C

choose random number with weight

int sum_of_weight = 0;
for(int i=0; i<num_choices; i++) {
   sum_of_weight += choice_weight[i];
}
int rnd = random(sum_of_weight);
for(int i=0; i<num_choices; i++) {
  if(rnd < choice_weight[i])
    return i;
  rnd -= choice_weight[i];
}
assert(!"should never get here");
Comment

PREVIOUS NEXT
Code Example
C :: increment and decrement operator 
C :: adding a node in the front on a linked list 
C :: C fscanf ignore commas 
C :: sleep in c 
C :: arduino empty serial buffer 
C :: refresh a chromebook terminal 
C :: print in c 
C :: command args c 
C :: c check if character is a digit or alphabet 
C :: bool c++ 
C :: scopes in c 
C :: windows make clean 
C :: C Syntax of realloc() 
C :: what is %d in C 
C :: hostbuilder add environment variables 
C :: gcc compiler for windows 10 
C :: c code to mips assembly converter online 
C :: left me on read 
C :: google business customer care number india 24/7 
C :: how to get out of function in c 
C :: worst fit program in c 
C :: Uri/beecrowd problem no - 1131 solution in C 
C :: Macro definition and expansion 
C :: when to add & in snacf c 
C :: getopt optstr 
C :: taking input and converting it to a string in c 
C :: C program to Increase 1 to all of the given Integer Digit 
C :: function declaration in c 
C :: come fare un programma in c con cui interagire 
C :: merge sort in c 
ADD CONTENT
Topic
Content
Source link
Name
8+6 =