FreeBSD Bugzilla – Attachment 85628 Details for
Bug 121885
random() system call returning the same number on amd64
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
random.c
random.c (text/plain), 923 bytes, created by
moggie
on 2008-03-19 22:30:00 UTC
(
hide
)
Description:
random.c
Filename:
MIME Type:
Creator:
moggie
Created:
2008-03-19 22:30:00 UTC
Size:
923 bytes
patch
obsolete
>#include <stdio.h> >#include <strings.h> >#include <stdlib.h> >#include <time.h> >#include <sys/types.h> >#include <unistd.h> > >int main(int argc, char ** argv) { > > srandom(time(0) * getpid()); > printf("time: %d\n", time(0)); > printf("pid: %d\n", getpid()); > > double r_num; > int i, percent = 50; > /* Constant 0x7fffffff is equal to (2**31)-1, which is the > * maximum value returned by the random() number function. > * http://web.mit.edu/answers/c/c_random_numbers.html 2008/03/19 */ > > for (i = 0; i < 100; i++) { > /*r_num = ((float) random() / (float) 0x7fffffff);*/ > r_num = random(); > > if (r_num < (percent / 100)) { > printf("random: %u - Dropped packet.\n",r_num); > } else { > printf("random: %u - Sent packet.\n", r_num); > } > } >} > >/* Sample program output: >random: 8440544 - Sent packet. >random: 8440544 - Sent packet. >random: 8440544 - Sent packet. >random: 8440544 - Sent packet. >random: 8440544 - Sent packet. >*/
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 121885
: 85628