• Models
  • Contests
  • Slicer
  • Login
  • Start Here
    thingiverse-iconprintables-iconcults3d-iconmakerworld-iconmyminifactory-icon

    3D GO

    3D ModelsContestsCollectionsSaved ModelsOn a mobile device?

3D GO

Privacy Policy
Hardware random number generator 3D Printer File Image 1
Hardware random number generator 3D Printer File Image 2
Hardware random number generator 3D Printer File Thumbnail 1
Hardware random number generator 3D Printer File Thumbnail 2

Hardware random number generator

Printerman avatarPrinterman

January 4, 2026

printables-icon
DescriptionCommentsTags

Description

This is a machine that throws 3 dice in a tray, with a stepper motor, and then reads the results using OpenCV. All programming is made in Python, code is mostly copied from older projects and ChatGPT.

Code works by using Blobdetection to find dots on the dice, and dbscan to cluster them into separate dice. The "separators" in the tray is needed for this to work.

Hardware used is a ordinary stepper motor, and a DRV8825 driver circuit. A Raspberry Pi 4 and a Pi Camera 3. Besides from a couple of M4/M2.5 screws most other parts are 3d printed using PLA and PETG.

Stepper motor

Im using a Bipolar stepper motor, NEMA 17. It is rated for 1,5 A but im limiting it to 500 mA with the DRV8825. The drive circuit is powered with 12 V.

Construction

I chose this version as the final machine, since it is quicker and gives better resutls than other machines i have built. It doesn't require any specialty parts like glass or bearings.

The machine is put together with CA glue and hot melt adhesive on a piece of bookshelf board.

Improvements to be made

  • The camera needs a bit wider angle, like the Pi Camera 3 Wide

  • To reduce noise levels, rubber bottom should be used in tray.

  • List dice after what lane it is placed in.

Random number generation

To get good random numbers from dice throws that give a value of 1-6 you can use modulo, but there are things to avoid. If you need a random value from 0 to 27 you should throw one three dice(d1-d3) in an order, and do the following:

(d1 - 1) * 36 + (d2 - 1) * 6 + (d3 -1) * 1

If the value is above 196 throw the dice again and remove the numbers, other wise there will be a modulo bias in the results. After that you modulo the number with 28. Example:

  • First dice thrown: 4

  • Second dice thrown: 3

  • Third dice thrown: 2

(4-1)*36 + (3-1)*6 + (2-1)*1 = 121

121 modulo 28 = 9

License:

Creative Commons — Public Domain

Related Models

#3DBenchy - The jolly 3D printing torture-test by CreativeTools.se preview image

#3DBenchy - The jolly 3D printing torture-test by CreativeTools.se

CreativeTools profile image

CreativeTools

90,912

Flying Night Dragon preview image

Flying Night Dragon

Sevro profile image

Sevro

8,745

Checklist personnalisable pour enfants preview image

Checklist personnalisable pour enfants

Mik3Dprint profile image

Mik3Dprint

1,271

The T-Rex Skull preview image

The T-Rex Skull

MakerBot profile image

MakerBot

39,829

Stable Flyer VI - Small Toy Glider preview image

Stable Flyer VI - Small Toy Glider

João Hackbart profile image

João Hackbart

3,746

ALPHABET PUZZLE - Montessori Letter Puzzle preview image

ALPHABET PUZZLE - Montessori Letter Puzzle

3DPTK.com profile image

3DPTK.com

776

Plantygon - Modular Geometric Stacking Planter for Succulents preview image

Plantygon - Modular Geometric Stacking Planter for Succulents

Printfutura profile image

Printfutura

28,537

Upcycled ATX Lab Bench Power Supply preview image

Upcycled ATX Lab Bench Power Supply

Caelestis Workshop profile image

Caelestis Workshop

1,518