| |

VerySource

 Forgot password?
 Register
Search
View: 1177|Reply: 9

How to generate a random number with uniform distribution in the interval (0, 1) in standard C? Is there a ready-made fu

[Copy link]

2

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-1-9 17:40:01
| Show all posts |Read mode
How to generate a random number with uniform distribution in the interval (0, 1) in standard C? Is there a ready-made function? !! !! !!
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-4-12 22:45:01
| Show all posts
double myRand () {
      return (double) ((double) rand () / ((double) RAND_MAX + 1) * 1);
}
Reply

Use magic Report

0

Threads

24

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-4-14 21:45:01
| Show all posts
Almost enough
No real random
Reply

Use magic Report

0

Threads

4

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-4-16 14:00:01
| Show all posts
Evenly distributed. . ?
Reply

Use magic Report

0

Threads

10

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

Post time: 2020-5-7 09:00:01
| Show all posts
double frandom () / * creat random numbers from 0 to 1 * /
{

return (double) rand () / (RAND_MAX + 1);
}
Reply

Use magic Report

0

Threads

5

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-5-9 03:00:01
| Show all posts
rand ()% 2
Reply

Use magic Report

2

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-5-21 09:15:01
| Show all posts
Thank you, but the randomness seems to be bad, too dense
Reply

Use magic Report

1

Threads

14

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-5-25 17:45:01
| Show all posts
Almost enough
No real random

Yes
Reply

Use magic Report

0

Threads

9

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

Post time: 2020-6-25 11:30:01
| Show all posts
Since it is random, "dense" is a matter of course
It’s as if you drag 100 people on the road at random, and their birthdays will also show a “dense” distribution
The chances of these 100 people's birthdays happening to be "evenly" distributed are quite small
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 France

Post time: 2020-6-28 10:15:01
| Show all posts
Since random is inherently without rules, dense and normal
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list