Assigning random values.

Hello forums, so i need to create a linked list in which each node is assigned a random value consisting of 0,5,20,100,500,1000,5000,10000 or 25000. So my question is how can i accomplish this task? Thanks for your time, if i need to add more info just ask. Thanks again.
Bump 4 help
closed account (ivDwAqkS)
do you just want only this values as randoms?
0,5,20,100,500,1000,5000,10000 or 25000.
Last edited on
closed account (ivDwAqkS)
if so, here you have the code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;

int arrays[9]= { 0, 5, 20, 100, 500, 1000, 5000, 10000, 25000};

int random(int n);

int main(){
    int i=9;
    int n;
    int x;
    srand(time(0));

    cout << "Press 0 to start: ";
    cin >> n;
    while(n==0){
        x = random(i);
        cout << "The random number is: " << arrays[x] << endl << endl;
        cout << "Press 0 to continue: ";
        cin >> n;
    }
    return 0;
}
int random(int n){
    return rand()%n;
}
Yes only those values. That looks good, ill see if i can work something like this into my function. Thanks alot man.
closed account (ivDwAqkS)
what do you mean with "something like this into my function"?
Like i said in the OP, i need to create a linked list in which each node is randomly filled with one of the 9 numbers. I need about 3 functions in my program and my first will be building the list. I was saying that your code was helpful in showing me how i can do random assignment.
Topic archived. No new replies allowed.