Hello everyone, so i am basically new to C++ coding and i am trying to write the randNum function in a way that it will give me these ranges The range for this row is: 1 to 10: 5 4 10 2 7 9 1 8 9 6 The range for this row is: 11 to 20: 20 15 16 11 20 11 13 13 13 11 The range for this row is: 21 to 30: 28 28 25 30 30 25 29 28 29 28 The range for this row is: 31 to 40: 39 33 34 40 37 …

Member Avatar
Member Avatar
+0 forum 2

How to set rand command, an integer from 3 to 50 (inclusive), but save it as a decimal number

Member Avatar
Member Avatar
+0 forum 2

Hi im trying to random showing items from data base and when echoed the same ones appear? If anyone could help that would be great. This is the query SELECT * FROM TABLE1, TABLE2 WHERE FIND_IN_SET(TABLE2.FIELD1, TABLE1.FIELD1) and `FIELDNAME` >= RAND() LIMIT 10

Member Avatar
Member Avatar
+0 forum 1

Hello, Somehow this is not working. I tried pretty much everything. I am also very new to PHP, but i made a nice CMS. Now I am making a website with some random flash-videos every time you refresh. This is what i got so far: <html> <head> <title>Sydcul.com</title> </head> <body> <h1>Sydcul.com</h1> <h2>Warning: flashing images!</h2> <p>It would be fun to turn on your sound.</p> <?php echo('This is visible, all stuff below is not. So the closing tags are not visible too.'); echo('<embed src="flash/' . rand(1, 5) . '.swf" type="application/x-shockwave-flash" width="320" height="240></embed>'); ?> </body> </html> I am not really sure how to …

Member Avatar
Member Avatar
+0 forum 4

Hey everyone I was working on a small tool and also refreshing my programming skills. my problem is I want to pick a random number from 60,000 to 200,000. it does that but the number it displays are not dramaticly changed. For example if it out puts 062045, i hit enter to do my while loop to reset it again and it moves up to like 062049.... i want it to go like if at one point its at lets say 62353, then i press enter to run again my while loop and it should change dramatically and maybe go …

Member Avatar
Member Avatar
+0 forum 5

Hi, I'm trying to preventing consecutive duplicate pages. For example when I refreshed a page it show a word from each page and when I refresh again it should show a different word from a different page not staying on one page. This is my pages: Page1 = Mozart Page2 = Bach Page3 = Choplin Page4 = Brahms Page5 = Beethoven Page6 = Schumann I'm using these functions: **rand()**, **shuffle()**, **sort()**, **array()**, for my code. This is my whole code so far: <?php $num=rand(1,6); shuffle($num); for ($m=0; $m<6; $m++) { $result[$m]=$num[$m]; sort($result); $m = array("page1.php" => "page1.php", "page2.php" => "page2.php", …

Member Avatar
Member Avatar
+7 forum 3

Hi, I have googled but found nothing about this. I am trying to generate a random number from a given array. But how do i do it? **Suppose:** I have an array `int arr[]={3,89,99,4,55};` and i want to generate a random number among these numbers. thanks in advance.

Member Avatar
Member Avatar
+0 forum 2

I have a list of about 500 names in a text file, i want to be able to get 5 random winners from this file. using C++ how do i do this

Member Avatar
Member Avatar
+0 forum 1

I have to create a game, in which the computer chooses randomly a word out of 5 and randomizes its characters, so that the user has to guess the word. He can also get a hint of the computer. I have started the code, but dont know how to continue: #include <iostream> #include<ctime> #include <string> #include <iostream> #include <ctype.h> #include <cstring> #include <locale> #include <math.h> #include <stdio.h> #include <stdlib.h> #include <time.h> using namespace std; int main() { char aword[6] = {'h','o','u','s','e','\0'}; char bword[11] = {'u','n','i','v','e','r','s','i','t','y','\0'}; char cword[9] = {'c','o','m','p','u','t','e','r','\0'}; char dword[5] = {'t','e','x','t','\0'}; char eword[8] = {'p','i','c','t','u','r','e','\0'}; char words[100]; strcat(words, …

Member Avatar
Member Avatar
+0 forum 1

Just what is wrong with this simple code of mine? [CODE]#include<stdio.h> #include<string.h> #include<stdlib.h> main() { int i=0, num; char a[8]; char keyword[8]; system("cls"); while(i<8) { num = rand()%3; if ( num == 0 ) a[i] = 65 + rand()%26; /* 65 is the ascii value of A */ else if ( num == 1) a[i] = 97 + rand()%26; /* 97 is the ascii value of a */ else a[i] = 48 + rand()%10; /* 48 is the ascii value of 0 */ i++; } printf("%s", a); printf("\n\nEnter the keywords : "); scanf("%s",&keyword); if (!strcmp(a, keyword)) { printf("The Same!"); getchar(); …

Member Avatar
Member Avatar
+0 forum 3

I wrote this simple code in devc++. On compiling, the computer is showing syntax error at line int P = rand(); ... while the same line, if I write in the main function gets compiled easily. Please tell me what's going on! [CODE]#include <stdio.h> #include <stdlib.h> #include <math.h> struct poclick { int P = rand(); }; int main () { int num = 4; // number of cases int nj; } [/CODE]

Member Avatar
Member Avatar
+0 forum 2

Ok, I need to make a program that randomly generates 4 random letters from 12 random letter and it cannot reapeat the same letter. for example you can only pick from a,b,c,d,e,f,g,h,i,j,k,l and the program can randomly generate a,b,c,d or b,c,d,e but should not generate a,a,b,b or something that repeats.Another is that a letter represents 1 animal. I'm new to rand() and srand() so any links on rand() srand() tutorial may help too. :) [CODE]#include<stdio.h> #include<stdlib.h> int main() { char a=ant,b=bear,c=cat,d=dog, e=emu,g=goat,l=lizard,m=monkey, p=parrot,r=rabbit,s=snake,t=tiger; int i; for(i=1,i<=4,i++) {printf("%c %c %c %c",&i &i &i &i); system("pause"); return 0; } [/CODE] so far …

Member Avatar
Member Avatar
+0 forum 5

Hi, I've been looking for a while for things that would give me random numbers under a value that I can specify (for me it's 5). I've seen [ICODE]rand();[/ICODE] and [ICODE]srand();[/ICODE]. I also know that[ICODE]srand()[/ICODE] is the seed and [ICODE]rand()[/ICODE] is the random number itself. Even the example programs don't work as expected (they don't return different numbers on each execution, I need it to return different numbers each time) Thanks, JT

Member Avatar
Member Avatar
+0 forum 3

hi, i have a small problem with the rand operator. at first i tried using it without srand but gave me the same value each time. i have inserted srand(time(0)); but my compiler throws me up these errors: 1>c:\users\ben\documents\university work\year 2\c++\code\myc++\spritelab\asteroidsgame.cpp(17): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>c:\users\ben\documents\university work\year 2\c++\code\myc++\spritelab\asteroidsgame.cpp(17): error C2365: 'srand' : redefinition; previous definition was 'function' 1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\stdlib.h(511) : see declaration of 'srand' im not sure what they mean. my top bit of code looks like this: [CODE]#include "wrapGame.h" #include <math.h> #include <time.h> #include …

Member Avatar
Member Avatar
+0 forum 6

Hello! I've got a little problem... I want to make a program which puts 10 random character, but the characters should NOT be digits. [CODE]#include <ctime> #include <stdio> #include <iostream> using namespace std; int main() { time_t t; time(&t); srand(t); int i,c; char ch; printf("Generating 10 random characters...\n"); for(i=1;i<=10;i++) { c=rand(); ch=c; printf("%c ",ch); } printf("\n"); system("PAUSE"); return 0; } [/CODE] I've got an idea, I could add a while and say [CODE] while(ch<ASCII HERE&&ch>ASCII HERE) { //generating random characthers } [/CODE] But I don't know how to use the ASCII... help?

Member Avatar
Member Avatar
+0 forum 3

Hello every one I'm trying to write a game that has a person guess a number between 1 and 100 hand have the computer guess that number via inputs from the user but I keep running into snags. [CODE]#include <iostream> #include <cmath> #include <cstdlib> using namespace std; int main() { srand ((unsigned)time(0)); int num, x, y, z; char ans, ans2; cout<<"Please pick a number between 1 and 100, are you ready \n"; cout<<"to begin? y or n"<<endl; cin>>ans; if (ans!='n') { do { y=100; z=1; x= rand () % y + z; cout<<"Is your number higher or lower then "<<x<<" …

Member Avatar
Member Avatar
+0 forum 5

[CODE] #include <iostream> #include <iomanip> #include <cstdlib> #include <ctime> using namespace std; int main () { int arr[9][9], n; srand(time(0)); for (int i=0; i<9; i++) { for (int j=0; j<9; j++) { n = rand() % 9; if (arr[i][j] == n) { n = rand() % 9; arr[i][j] = n; } arr[i][j] = n; } } for (int i=0; i<9; i++) { for (int j=0; j<9; j++) { cout<<" "<<arr[i][j]; } cout<<endl<<endl; } system ("pause"); return (0); } [/CODE] I want to generate unique numbers in the 9 by 9 array. The numbers should be in the range from 1 …

Member Avatar
Member Avatar
+0 forum 9

solved

Member Avatar
Member Avatar
+1 forum 1

Call me a noob, but is there a way to use [B][I][U]just[/U][/I][/B] PHP to create a photo slideshow? Or do you need to use flash? I have code that will display images in a random sequence, which is fine. [CODE=php]<?php $pic = rand(1,15); print "<img src=\"images/$pic.jpg\" height=\"100\" width=\"140\" />"; ?>[/CODE] But this is in the middle of other elements on a web page. So I need to find a way to make the images change without refreshing the page. Thanks in advance.

Member Avatar
Member Avatar
+0 forum 2

Basically what I'm trying to do is simple. My main problem is the random numbers, but in the comments i have some other issues... if you know how to fix them that would be great the other two main ones im having trouble with are: the do loop until the monsters health is 0, and once the code ran, having the user press any key to go back to the starting fight menu. back to the main problem: based on the "monsters" level it will do a random amount of damage.. for example: the monsters level is 3. [CODE]void fightd …

Member Avatar
Member Avatar
+0 forum 3

I'm trying to create a random float generator. The float must be 2 decimal places and between the values 0.50 and 999.99. I tried casting rand() to a float below, which didn't work. I'd still like to know the reason this didn't work. [CODE] saleAmount = ((float)rand() % 99950.00 + 50.00 ) / 100.00; [/CODE] To make rand() a float with 2 decimal places, I did the following, which did work. [CODE] saleAmount = rand()*1.01; [/CODE] I've also tried using fmod, however I can't figure out how to get the outcome between the 2 boundaries. Any suggestions or helpful tips? …

Member Avatar
Member Avatar
+0 forum 2

Hello I have a > b(for example) I need to generate random number x that belongs from a to b for example a = 9, b = 16 x has to be x > 9 and x < 16 I use cstdlib.. but can't guess how to do it (using rand()) can you do it, without any while or for?? this is a part of a huge program... so I have to do it carefully, this my program doesn't work.. I think the reason is that... this is a part of my program ... the excercise was about a game …

Member Avatar
Member Avatar
+0 forum 9

currently i am writing a text based RPG but, when i call for the fight my rand() either does not seed each time or it glitches to continuously gets the "Boar". if you could please take a look at it and see if the problem is in the coding, i would be grateful. *note: this segment is still under construction. i am still trimming down the fatty extras. [CODE] int BattleAthens(int& C_Health,int& C_weapon,int& C_Exp,int& C_Gold,int& C_Dollars) { int E_Number = 0, E_Health = 0, E_Exp = 0, E_Gold = 0, E_Dollars = 0, E_DMG = 0; string E_Name; //string E_Name2; …

Member Avatar
Member Avatar
+0 forum 4

This is the code I have so far. I can't even get the numbers range to print to the screen correctly. I am very new to all this stuff so go eacy on me. Can anyone help?? [code=c] #include <stdio.h> #include <stdlib.h> #include <math.h> #include <time.h> int main() { unsigned int lo, hi; int comp; double tries = 0; double guess = 0; printf ("Please enter two integers for the range:\n"); scanf ("%d%d", &lo, &hi); srand (time(0)); comp = lo + rand() % (hi - lo); printf ("I'm thinking of a number between %d and %d!\n", lo, hi); scanf ("%f", …

Member Avatar
Member Avatar
+0 forum 2

I am using the code as under but always getting 0 value means the same folder [code=php] $random_folder=array("folder1","folder2","folder3"); $folder=$random_folder[rand(0,count($random_folder)-1)]; [/code] Getting folder1 always.. What's wrong?? Please Help.......

Member Avatar
Member Avatar
+0 forum 7

hi i would like u to tell me if i can make a random function to choose between four numbers and only them(-1 , 1 , -10 ,10)

Member Avatar
Member Avatar
+0 forum 7

Hello Every one ! This program is producing some strange output as it is only generating x = 6 :(,can some through some light that why is it behaving like this ? [code] #include <iostream> #include <stdlib.h> using namespace std ; main () { // Random Number Program int num,x ; cout << "Please Enter a no between 1 to 6 " ; cin >> num ; x = rand() % 6 + 1 ; if ( num == x) cout << "Congratulations!You WON " ; else cout << " You Lose " ; } [/code]

Member Avatar
Member Avatar
+0 forum 4

Hi all, I have tried to make a little example of a random number generator for c++. However, as I am quite new in this language I do not know its peculiarities. Here is the code [CODE] //g++ -o ran ran.cpp #include <iostream> using namespace std; int main () { int num; for (int i = 0; i < 10; i++) { num = rand() % i; cout << num << endl; } } [/CODE] This little code gives the above error. I have tried replacing the "i" variale with an specific number and it works. Can anybody tell me …

Member Avatar
Member Avatar
+0 forum 4

Hi, I have a bit of a strange problem where I am unable to "echo" results from a database - I will show you the code then explaine what im trying to do [code] <?php include_once "connect_to_mysql.php"; $sql = mysql_query("SELECT * FROM table ORDER BY RAND(), LIMIT 1"); while($row = mysql_fetch_array($sql)){ $add = $row["add"]; $link = $row["link"]; $title = $row["title"]; echo " <b>$add</b> <a href='$add'$link</a> "; } ?> [/code] db has the following fields id, add, link, title The script to connect to the database works fine, as if i change the host, it gives me an error. But im …

Member Avatar
Member Avatar
+0 forum 4

The End.