473,327 Members | 2,016 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Question about pseudo random numbers

I have a program that allows a user to guess a number 5 times. How can I create the number using a pseudo random number rather than "pre-defining" the numbers. The number has to be between 1 and 20??

Any help would be greatly appreciated.
Oct 23 '08 #1
2 1372
JosAH
11,448 Expert 8TB
Have a look at the srand() and rand() functions; they're part of the standard library.

kind regards,

Jos
Oct 23 '08 #2
#include<stdlib.h>//contains random functions and RAND_MAX
#include<time.h>//contains time
srand(time(0));
number=rand()%20+1;

You know, you don't have to post this question here and wait till(or if) someone answers it, you can just google it.
Oct 23 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

14
by: Paul C-T | last post by:
Hi, Is there a way to repeat a set of code until a certain if statement is satisfied. If it is then to exit the loop and if not repeat the code? Say I want to write a card game application in...
3
by: Rob | last post by:
He , I need to generate some random numbers, right now I am using: Random pk = new Random(); int a = pk.nextInt(540); and wondering if there is any other methods in java to generate random...
23
by: hedylogus | last post by:
I've just begun learning C++ and I'm trying to write a program to shuffle a deck of cards. I've succeeded....for the most part....but every now and then rand() produces duplicate random numbers...
6
by: Graeme | last post by:
I am writing a simple windows matching game with cards and pictures (ie "concentration"). In order to write something like this, I need to be able to give each "card" a random position in the...
7
by: Ioannis Vranos | last post by:
I want to create some random numbers for encryption purposes, and i wonder if the following scheme makes it more hard to guess the underneath number generation pattern, than the plain use of...
1
by: Wavelet | last post by:
If I use srand(value) to change the random seed, when I close the vc or run the code from the beginning, the seeds of random will change to default value or still keep the value of what I designed...
1
by: Ellen Manning | last post by:
I've got an A2K database with a report that generates any number of random medical record numbers. The user inputs how many numbers they want and report uses the Randomizer function found on "The...
70
by: Ben Pfaff | last post by:
One issue that comes up fairly often around here is the poor quality of the pseudo-random number generators supplied with many C implementations. As a result, we have to recommend things like...
21
by: Marc Dansereau | last post by:
Hi all I am new to this forum and to the c programming language. If I understand, the random() function in C return numbers that follow a uniform distribution U(0,1). Can somebody know how to...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.