• Are you planning to upload your awesome tool to Hive? Please review the rules here.
    July 9, 2018: The rules for the Tool Section have been revised. Please be sure to read the revisions.

Text Shuffler

This bundle is marked as useful / simple. Simplicity is bliss, low effort and/or may contain minor bugs.
Simply shuffles 1 line of text

Drag file with the line of text to be shuffled on top of it
Notepad will start up, displaying the shuffled line of text, cnp out of notepad

Repeat to shuffle again

Does 150000 shuffles per run

Very simple code ^)^
Code:
#include <iostream>
#include <time.h>
#include <random>
#include <fstream>
#include <string>

using namespace std;

int main(int argc, char* argv[]) {
	string line;
	ifstream input;
	ofstream output;

	if (1 == argc) { return 0; }

	input.open(argv[1]);
	if (input.is_open()) {
		getline(input, line);
		input.close();

		if (line.length() > 0) {
			int shuffles = 150000;
			int swap;
			char c;
			srand((unsigned int)time(NULL));
			for (unsigned int i = 0; i < line.length(); ++i) {
				swap = rand()%line.length();

				c = line[i];
				line[i] = line[swap];
				line[swap] = c;
			} //for

			output.open("output.txt");
			output << line;
			output.close();
			system("notepad.exe output.txt");
			system("del output.txt");
		} //if
	} //if

	return 0;
} //main

Keywords:
shuffle
Contents

Text Shuffler (Binary)

Reviews
08:23, 17th Mar 2013 Magtheridon96: Refer to my post in the thread. Also, this doesn't do 150000 shuffles :v

Moderator

M

Moderator

08:23, 17th Mar 2013
Magtheridon96: Refer to my post in the thread.
Also, this doesn't do 150000 shuffles :v
 
Nes, since most people are having problems using this, I took the liberty of rewriting your code in C.

C:
#include <stdio.h>
#include <cstdlib>

int main(int argc, char* argv[]) {
	unsigned int length = 0;
	unsigned int size = 64;
	char* buffer = (char*)malloc(size);
	FILE* file;
	char c;

	if (1 == argc) {
		return 0;
	}

	file = fopen(argv[1], "rb");

	if (file) {
		/*
		*	Put all characters into a buffer.
		*	This will stop upon:
		*
		*		- Reaching the end of the file
		*		- Hitting a carriage return character.
		*		- Hitting a linebreak character.
		*/
		while (true) {
			c = fgetc(file);

			if (c != EOF && c != '\r' && c != '\n') {
				if (size == length) {
					buffer = (char*)realloc(buffer, size += 64);
				}
				buffer[length++] = c;
			} else {
				break;
			}
		}
		fclose(file);

		/* Skip if line has length = 0 */
		if (length) {

			int shuffles = 50;
			int swap;

			/* Seed random number generator */
			srand((int)&argc);

			/* Shuffle */
			while (shuffles--) {
				for (unsigned int i = 0; i < length; i++) {
					swap = rand() % length;

					c = buffer[i];
					buffer[i] = buffer[swap];
					buffer[swap] = c;
				}
			}
			
			/* Write file */
			file = fopen("TextShufflerOutput.txt", "wb");
			for (unsigned int i = 0; i < length; i++) {
				fwrite(&(buffer[i]), 1, 1, file);
			}
			fclose(file);

			/*
			*	These calls are highly unportable.
			*	They are only being used because this 
			*	is meant to run *only* on Windows.
			*/
			system("notepad.exe TextShufflerOutput.txt");
			system("del TextShufflerOutput.txt");
		}
	}

	return 0;
}

The .exe attached is only 7KB too :D
 

Attachments

  • TextShuffler.zip
    3.5 KB · Views: 60
Top