Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Generate random number - Help

Status
Not open for further replies.

Maverickmax

Advanced Member level 1
Joined
Dec 6, 2004
Messages
404
Helped
8
Reputation
16
Reaction score
3
Trophy points
1,298
Activity points
3,689
Hello

I am struggling to generate random number in term of binary number such as 1 and 0. Bascially I would like to generate 1 or 0 up to max 10 binary in C (for example, 1010111101). I would be very grateful if someone can provide me simple code in C.

MM
 

Hi,


try with "rand" function in C.

Example:

#include <stdlib.h>
unsigned int result;

.....


result = rand(0x1111);


here it is from Keil help:

The rand function returns a random number in the range 0 to +32767. The random number generator is reinitialized each time a non-zero value is passed in the seed argument. You may use the rand function to delay for a random number of clock cycles or to generate random data to feed into a particular algorithm or input routine.

Example
>rand (0x1234) /* Initialize random generator with 0x1234 */
0x3B98

>rand (0) /* No initialization */
0x64BD


BTW: Which mcu u r using?!?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top