mozzi_rand cannot go full range

Open
#220 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
arduino, c
Domain
embedded-iot

Research direction

Start by locating the uint8_t and unsigned int rand(uint8_t maxval) and rand(unsigned int maxval) implementations, then inspect the xorshift path they use. Check how full-range values are represented and verify that the proposed API can generate the datatype's maximum value without requiring a union; the issue provides no test file or named source file.

Written by the indexing model from the issue text.

Description

uint8_t rand(uint8_t maxval)

The largest value that can be passed into this function is 255, which means that the largest possible random number that can be generated is 254.

unsigned int rand(unsigned int maxval)

The largest value that can be passed into this function is 65535, which means that the largest possible random number that can be generated is 65534.

The alternative is to call xorshift directly and mask out the value. But there ought to be versions of these functions which provide full range for the datatypes. Furthermore, calling xorshift means I have to do a bit conversion to get an int8_t or int16_t, so I get to build a union.

Dominant language
C
Stars
1.3k
Forks
204
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from sensorium/Mozzi

All issues in sensorium/Mozzi

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.