string

i am trying to generate random ss number as a string by using the rand[] fuction with heap sorting method how do I go about to do that
Last edited on
What is a "random ss number"? The function rand() returns an integer from 0 to RAND_MAX (which is at least 31768). You have to initialize it with "srand()" first.

To convert this number into a string, you can use std::stringstream.

But what has heap sorting to do with that? :-O


Ciao, Imi.
But what has heap sorting to do with that? :-O ... same interest here^^...

I would guess, that he ment:
1
2
3
stringstream ss;
 ss << number;
  ss.str();
What is a "random ss number"?

i am using en numbers and i am generating diferent social security numbers
u can use this for random number generation

An example of a simple pseudo-random number generator that is computationally fast, has good (albeit not cryptographically strong) randomness properties, is given by the following "Multiply-With-Carry" generator.


m_w = <choose-initializer>; /* must not be zero */
m_z = <choose-initializer>; /* must not be zero */

uint get_random()
{
m_z = 36969 * (m_z & 65535) + (m_z >> 16);
m_w = 18000 * (m_w & 65535) + (m_w >> 16);
return (m_z << 16) + m_w; /* 32-bit result */
}
what i really want to do is that i am generating randomly social security number but i have to use a sorting method (heap or selection sort). each ssn have to be stored as a string and must be distinct the time complexity is very important
A selection sort is easier to implement, but a heap sort is faster.

For your random number generator, try seeding it using time() from time.h.

http://en.wikipedia.org/wiki/Heap_sort
http://en.wikipedia.org/wiki/Heap_(data_structure)
http://en.wikipedia.org/wiki/Selection_sort
http://cplusplus.com/reference/clibrary/ctime/

-Albatross
Last edited on
I am trying to write this program to get random ssn using selection sort but I think i am doing it wrong. Havent write orgrams in a long time

#include<string>
#include<iomanip>

#include<iostream>
using namespace std;
const int MAX_SSN = 100;
char inputArray[MAX_SSN][10],tempArray[MAX_SSN];
char ssn[10];
int main()
{
int inputSSN[MAX_SSN];// declaring an interger array
struct NodeType
{
char ssn;

void seclectionSort(int largest, int 10)
{
int i,j,largest,sorted, unsorted;

for(i=1; i<=10;i++)
{
largest=unsorted[i]

for(j=10;j<=1;j--)

if(unsorted[i]>largest)

sorted[j]=largest;
}
//int temp=largest;
//largest=sorted[j];
//sorted[j]=temp;


//{
//char ssn[10];
//NodeType*next;
//};
//NodeType*List;
//ssn[k]='0' + rand()%10;
Topic archived. No new replies allowed.