Skip to main content

Pseudo Random List Generator

Project description

Pseudo Random List Generator (PRLGEN) v2.0

Motivation & Aim

Experimental psychologists and linguistics researchers require unbiased, high-entropy stimulus lists for experiments involving human language production. The human brain is highly sensitive to patterns and adapts quickly, which can introduce bias and affect response times in experimental results. PRLGEN maximizes entropy in stimulus presentation, resetting participant expectations and minimizing statistical bias by ensuring that items of the same group or category do not appear consecutively beyond a controlled threshold.

This tool is designed to:

  • Randomize stimulus lists for psycholinguistic and cognitive experiments
  • Avoid consecutive repetitions of the same experimental condition (unless allowed)
  • Automatically determine the minimal feasible repetition threshold if the requested constraint is impossible
  • Integrate seamlessly with Python-based experiment platforms like PsychoPy

Features

  • Command-line and library usage
  • Professional, robust error handling and feasibility checks
  • Returns both the randomized list and the minimal repetition value used
  • Optimized for speed and memory, suitable for large input lists

Installation

Install via pip (after packaging):

pip install prlgen

Usage

Command line:

prlgen -f input.csv -t 0 -c 1 -k 1 -n output -o 1

Arguments:

  • -f, --file: Input CSV file
  • -t, --trial: Trial ID column index (default: 0)
  • -c, --cond: Experimental condition column index (default: 1)
  • -k, --repetition: Max allowed consecutive repetitions (default: 1)
  • -n, --name: Base name for output files
  • -o, --outnum: Number of lists to generate

If the requested repetition constraint is impossible, PRLGEN will automatically increase the allowed consecutive repetitions to the minimal feasible value and report this value in the output.

Library Usage

from prlgen import create_random_list
output_list, min_k = create_random_list(input_list, cond_col, trial_col, k)
# output_list is the randomized list
# min_k is the minimal feasible repetition value used

Integration Example: PsychoPy

See examples/example_1.py for a ready-to-use integration with PsychoPy.

Documentation & Proof of Correctness

Full API documentation is available in the docs/ folder. The mathematical proof of correctness is provided in the proof/ folder (LaTeX and PDF, CC-BY license).

License

GPL v3.0 for code, CC-BY for proof documents.

Example code is available in the examples folder to show how to add it to your PsychoPy project. The output list is ready to be used in your main presentation loop. It won't change the column order or touch any row content. It will shuffle the order of the items in the list to match the pseudo random criteria.

The module interface (check the example and comments in the example code) allows the user to set the parameters:

  • The input list, as a list of list in Python [[list], [list], ...]. Usually it is parsed from an input CSV file.
  • The column index of the list with unique trial id, or trial number. By default, the value is the first column or column zero.
  • The column index that stores the experimental condition code. It has to be different than the trial id index.
  • The number of consecutive stimuli of the same condition that can appear in the output list. By default, the value is one.

This last parameter can be set above one. It may be desirable when the input list is populated with different fillers as experimental conditions and they don't match the same number of items as the other conditions.

The module assumes by default that the trial number column is the first column of the list and the desired repetition is 1 (one), that is, you don't want more than 1 trial of the same condition being presented consecutively.

The module will check if the number of items in each experimental condition are enough to build a pseudo random list with the desired repetition parameter. It will trigger an error and stop your script if the list is impossible to build and it will inform you about the problem. Furthermore, an incorrect trial number column, i.e., not unique values in each row, an incorrect experimental condition column, or zero or negative values for the repetition, will trigger an error and stop the script.

The code is released as GPL v3.0 to allow it to be integrated with PsychoPy.

A proof of correctness of the algorithm is available as a Latex document in the proof folder. Thus, it is possible to implement the algorithm in any other programing language with enough expression power. The tests code implements the function described in the proof document under the correctness paragraph for k consecutive elements. Any new implementation should also validate the correctness using the same function in the target language.

The Latex document in the proof folder is under Creative Commons Attribution Licence, CC-BY.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

prlgen-2.0.1.tar.gz (26.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

prlgen-2.0.1-py3-none-any.whl (18.9 kB view details)

Uploaded Python 3

File details

Details for the file prlgen-2.0.1.tar.gz.

File metadata

  • Download URL: prlgen-2.0.1.tar.gz
  • Upload date:
  • Size: 26.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.6

File hashes

Hashes for prlgen-2.0.1.tar.gz
Algorithm Hash digest
SHA256 2cb3bdb0d49d6cc5ca5957565286286ebae9ce633c4640a094fa6760bc87d54d
MD5 e410f2c74929bd00cc5a0645aaff9ec8
BLAKE2b-256 d392a35320aa4e175e007c9c18544d3fa353212737457e44418737f442f9cdf3

See more details on using hashes here.

File details

Details for the file prlgen-2.0.1-py3-none-any.whl.

File metadata

  • Download URL: prlgen-2.0.1-py3-none-any.whl
  • Upload date:
  • Size: 18.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.6

File hashes

Hashes for prlgen-2.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5123dedf418581cfb7c514c688c235d72e5a66d25795b2830b7635a51fd999b9
MD5 b83ef4602cbcc5643de6de4516910193
BLAKE2b-256 55db7feff4834f150edd1766c907272e6046f2f0e317be2cbc2c6076b1ae03f5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page