> For the complete documentation index, see [llms.txt](https://docs.zongsoft.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.zongsoft.com/documentation/en/framework/core/common/randomizer.md).

# Randomizer

Explain the real purpose of the random string in the body file name of Discussions.

Randomizer provides random bytes, integers and strings. Discussions uses a random string as part of the file name to avoid sharing the same file name when new content has not yet obtained a database number.

Source: [src/Services/PostService.cs](https://github.com/Zongsoft/Zongsoft.Discussions/blob/main/src/Services/PostService.cs#L222) (excerpt; see source for context).

{% code title="PostService.cs" %}

```csharp
protected virtual string GetContentFilePath(ulong postId, string contentType)
{
	return Utility.GetFilePath(string.Format("posts/post-{0}-{1}.txt", postId.ToString(), Zongsoft.Common.Randomizer.GenerateString()));
}
```

{% endcode %}

PostId provides business clues, and the random suffix reduces the chance of path conflicts with the same number or unallocated numbers. The path also goes through Utility.GetFilePath plus configuration and user scope. Random file names are not a substitute for access control and do not constitute a guarantee of absolute uniqueness.

## Method Selection

| method                                       | function                                          |
| -------------------------------------------- | ------------------------------------------------- |
| Generate                                     | Random bytes of specified length                  |
| GenerateInt16、GenerateInt32、GenerateInt64    | signed integer                                    |
| GenerateUInt16、GenerateUInt32、GenerateUInt64 | unsigned integer                                  |
| GenerateSecret                               | key style string                                  |
| GenerateString                               | Ordinary random string, can be limited to numbers |

This business does not directly use GenerateSecret as a credential, so the file naming method cannot be directly promoted as an authentication token scheme. See [RandomizerTest](https://github.com/Zongsoft/framework/blob/main/Zongsoft.Core/test/Common/RandomizerTest.cs) for framework use cases for string length and character range.

Related reading: [file system](/documentation/en/framework/core/io.md), [Write Operations](/documentation/en/framework/data/writing.md).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.zongsoft.com/documentation/en/framework/core/common/randomizer.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
