# How to define a cube unit based on Graphics3D [duplicate]

I would like to ask,how can we draw 50 spheres of radius 0.1 (randomly) in the unit cube.

This is my first try,

Graphics3D[
Table[{Red, Sphere[RandomReal[{0.1, 0.9}, 3], 0.1]}, {50}],
PlotRange -> {0, 1}]


To define a unit cube is this enough???

• Looks like this is a question from the quiz questions for the Wolfram-U "Programming Fundamentals Week 4" course here. – Rohit Namjoshi Jun 14 at 18:17

A few alternatives you might consider:

1. You can generate random centers using a single call to RandomReal:
Graphics3D[{Red, Sphere[RandomReal[{0.1, 0.9}, {50, 3}], 0.1]},
PlotRange -> {0, 1}] 1. You can transform Cuboid[] and use it with RandomPoint as follows:
r = .1;

transformedCuboid = Cuboid[r {1, 1, 1}, (1 - r) {1, 1, 1}];

centers = RandomPoint[transformedCuboid, 30];

Graphics3D[{PointSize[Medium], Point@centers,
Opacity[.5, Red], Sphere[#, r] & /@ centers,
EdgeForm[Blue], FaceForm[], Cuboid[],
EdgeForm[Green], transformedCuboid}] • what is the error in my proposed code? – ABCDEMMM Jun 14 at 17:54
• can we fine the color inside the command "Sphere"? – ABCDEMMM Jun 14 at 18:01
• @ABCDEMMM, I don't see any error in your code. – kglr Jun 14 at 18:01