![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Sequence number generation on a key column | sbasetty | Shell Programming and Scripting | 6 | 03-27-2008 09:09 AM |
| generate random number in perl | zx1106 | Shell Programming and Scripting | 2 | 03-17-2008 09:13 PM |
| Random number generation in ksh | mervin2006 | UNIX for Dummies Questions & Answers | 2 | 04-26-2007 11:02 PM |
| SQL Loader Auto Number Generation | vinoth_kumar | UNIX for Dummies Questions & Answers | 2 | 08-01-2006 05:40 AM |
| How to generate a random number? | MacMonster | High Level Programming | 2 | 10-15-2001 09:35 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
Random number generation
Hi...How can I generate random numbers between a given range ...preferably between 1 and 100...in UNIX C programming...?
I tried out functions like rand(),drand48() etc but didnt get satisfactory results... Thanks a lot in advance.......... |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
Would you please explain what do you mean by unsatisfactory? I suppose most applications generate random numbers with these functions for cross-platform compatibility as they are standard.
In the rand() manpage, somewhere in the bottom, there is a note that discusses how to use that properly. Did you use it like that? http://linux.com.hk/penguin/man/3/ra...on=3&name=rand On some systems there are other means for random number generation. For instance, on Linux PCs the /dev/hwrandom represents a hardware random number generator . But this is only present if this support is compiled and available in the kernel. You may also try /dev/random and /dev/urandom. http://linux.com.hk:80/penguin/man/4/random.html Code:
cbkihong:~# cat /dev/random | hexdump 0000000 1169 ce30 3785 5b36 7afe 84ff e6f6 e637 0000010 ea63 90b5 1f59 bf52 4296 b4c1 c129 5416 0000020 2940 608e 5fed e724 fd0e 4f92 3d75 4de5 0000030 1c6f 4d22 80bf fedf a208 ff41 5163 c146 0000040 838e 9ab2 fa6d 5b51 0715 ea56 d630 99dd 0000050 6b70 2ff3 11f6 feb6 3e17 b241 e5b9 dafb 0000060 e2fd 78cd c1d2 ed64 970c e5f4 fcf1 0fad 0000070 55c0 b395 629d a43d abc1 5b1d ad28 515f 0000080 72d0 8d68 bd22 5d19 171e 4f6b d28a 9bf2 0000090 f7a0 016a 8ba9 be22 8473 34ee 3f67 3c7c 00000a0 a5ce a23c 3b36 2463 cc94 99b2 fc91 0991 |
|||
| Google The UNIX and Linux Forums |