Skip to content
Authors

File prod_weighted.c

FileList > prod_weighted > src > prod_weighted.c

Go to the source code of this file

Defines the functionality of a weighted production. More...

  • #include "prod_weighted.h"
  • #include <stddef.h>
  • #include <stdlib.h>
  • #include <string.h>
  • #include <pdgl_defs.h>

Public Functions

Type Name
const char * prod_weighted_resolve (const void * config)
The resolve function for the weighted production type.
STATIC_INLINE const char * prod_weighted_select (prod_weighted_pair_t * pairs, size_t pairs_len)
Select by weighted random selection a string from a list of string/weight pairs.
STATIC_INLINE uint64_t prod_weighted_sum (prod_weighted_pair_t * pairs, size_t pairs_len)
Compute the sum of the weights for an input list of string/weight pairs.
const char * prod_weighted_terminate (const void * config)
The resolve function for the weighted production type.
STATIC_INLINE uint64_t rand_uint64 (void)
Select by weighted random selection a string from a list of string/weight pairs.

Macros

Type Name
define IMAX_BITS (m) ((m) / ((m) % 255 + 1) / 255 % 255 \* 8 + 7 - 86 / ((m) % 255 + 12))
Posted by chux, modified by community. See post 'Timeline' for change history Retrieved 2026-03-11, License - CC BY-SA 4.0.
define RAND_MAX_WIDTH [**IMAX\_BITS**](prod__weighted_8c.md#define-imax_bits)(RAND\_MAX)
Posted by chux, modified by community. See post 'Timeline' for change history Retrieved 2026-03-11, License - CC BY-SA 4.0.

Detailed Description

Author:

Joe Starr

Public Functions Documentation

function prod_weighted_resolve

The resolve function for the weighted production type.

const char * prod_weighted_resolve (
    const void * config
) 

Resolve at random a replacement string.

Parameters:

  • config A configuration of a production.

Returns:

A pointer to the output of the resolution.


function prod_weighted_select

Select by weighted random selection a string from a list of string/weight pairs.

STATIC_INLINE const char * prod_weighted_select (
    prod_weighted_pair_t * pairs,
    size_t pairs_len
) 

Compute the sum of the selection weights. Then compute a random integer \(r\) between 0 and the sum. Determine which partial sum holds \(r\) and report that string.

Parameters:

  • pairs A list of string/weight pairs.
  • pairs_len The length of the input list.

Returns:

The selected string or NULL on an error.


function prod_weighted_sum

Compute the sum of the weights for an input list of string/weight pairs.

STATIC_INLINE uint64_t prod_weighted_sum (
    prod_weighted_pair_t * pairs,
    size_t pairs_len
) 

Parameters:

  • pairs A list of string/weight pairs.
  • pairs_len The length of the input list.

Returns:

The sum of the weights from the list.


function prod_weighted_terminate

The resolve function for the weighted production type.

const char * prod_weighted_terminate (
    const void * config
) 

Terminate at random with a terminal string.

Parameters:

  • config A configuration of a production.

Returns:

A pointer to the output of the resolution.


function rand_uint64

Select by weighted random selection a string from a list of string/weight pairs.

STATIC_INLINE uint64_t rand_uint64 (
    void
) 

Posted by chux, modified by community. See post 'Timeline' for change history Retrieved 2026-03-11, License - CC BY-SA 4.0

Returns:

A random uint64


Macro Definition Documentation

define IMAX_BITS

Posted by chux, modified by community. See post 'Timeline' for change history Retrieved 2026-03-11, License - CC BY-SA 4.0.

#define IMAX_BITS (
    m
) `((m) / ((m) % 255 + 1) / 255 % 255 * 8 + 7 - 86 / ((m) % 255 + 12))`


define RAND_MAX_WIDTH

Posted by chux, modified by community. See post 'Timeline' for change history Retrieved 2026-03-11, License - CC BY-SA 4.0.

#define RAND_MAX_WIDTH `IMAX_BITS (RAND_MAX)`



The documentation for this class was generated from the following file source/prod_weighted/src/prod_weighted.c