Solving Math Algorithm Problem with rand(1,1) Function

  • Context: Mathematica 
  • Thread starter Thread starter sapiental
  • Start date Start date
  • Tags Tags
    Algorithm Mathematical
Click For Summary
SUMMARY

The discussion centers on implementing a random selection algorithm using the function rand(1,1) to choose between options A, B, and C. The user initially assigns A = 1:3, B = 4:6, and C = 7:9 but encounters an issue with the function returning 0. A suggestion is made to re-generate the random number if 0 is produced, which maintains the even distribution of choices among A, B, and C. The consensus is that this approach preserves randomness, yielding each option with an equal probability of 1/3.

PREREQUISITES
  • Understanding of random number generation functions, specifically rand(1,1)
  • Basic knowledge of algorithm design and implementation
  • Familiarity with probability distribution concepts
  • Experience with conditional statements in programming
NEXT STEPS
  • Explore the behavior of the rand() function in different programming languages
  • Research methods for ensuring uniform distribution in random selection algorithms
  • Learn about alternative random number generation techniques, such as using a seed
  • Investigate the implications of re-generating random numbers on overall randomness
USEFUL FOR

Software developers, algorithm designers, and anyone interested in implementing random selection methods in programming.

sapiental
Messages
110
Reaction score
0
Hello

I have to write an algorithm that randomly chooses between A B and C.

I have to use the function (rand(1,1) which gives me a radndom number from the following (0,1,2,3,4,5,6,7,8,9)..

I was thinking of assigning A = 1:3 B = 4:6 C = 7:9

But I run into the problem of the random function giving me a 0.
Could I just write a statement saying that if I get a 0 from the random number generator, to generate anohter number? Would this still remain truly random using the function rand(1,1)?

Any help or suggestions are much appreciated. Thank you!
 
Physics news on Phys.org
That should be fine. Unless rand completely sucks ass, there should always be an essentially even chance of getting any of those numbers. Since you'll get an A 3/10 of the time, B 3/10 of the time, and C 3/10 of the time, and pick again 1/10 of the time, you get A 1/3, B 1/3, and C 1/3 of the time
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 2 ·
Replies
2
Views
6K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 3 ·
Replies
3
Views
3K
Replies
3
Views
7K
  • · Replies 1 ·
Replies
1
Views
2K