문자(이름)에 고유 번호 넣는 방법

wodnrrns의 이미지

간단한 웹 APP 을 만들어보려고 하는데요.

사람 이름을 입력하면, 고유한 결과를 보여주고 싶습니다.
가령 오늘의 운세라고 한다면,

그 이름을 입력하면 언제나 같은 결과가 나왔으면 좋겠는데,

이름만을 가지고 KEY로 사용하려니 어렵네요. 분포는 대략 3000건 정도인데,

그냥 바이트 배열로 바꿔서 숫자로 변경하자니.. 한쪽으로 치우칠것 같고...

질문이 좀 장황하네요,

간추려보면, 사람이름 입력이 왔을때 동일한 결과값을 보여주고 싶습니다. 그리고 Case 가 총 3000건 정도인데, 한쪽으로 치우치지 않고
고르게 보여줄 수 있는 방법이 있을까요?

cinsk의 이미지

이름을 input으로 hash하면 되겠네요.

wodnrrns의 이미지

정해진 이름군이 있다면 말씀하신것과같이 할 수 있을텐데요,
위에 말씀드린것곽 타이 web app 형태로 만들고 사람들이 접속해서 이름을 치면 해당 결과로 연동되는 형태로
개발할거라 미리 어떤 인풋이 들어올지는 모르는 상태여서 hash 하는게 어떤 의미가 있을지 모르겠네요.

input 이 고정이라면 hashing table 만들어놓고 맵핑 시키면 되겠지만요..

Prentice의 이미지

echo wodnrrns | md5sum -b > results.txt

a2cb3f99ebccf1b8c8421ae48c95167c *-

요런 cryptographic hash를 말씀하시는 듯합니다. 이런 거라면 웬만해서는 안 겹칠 테니까요.

ymir의 이미지

이름을 input 으로 hash 함수를 돌리고, 특정 범위의 숫자(예, 0 ~ 3000) 가 나오도록 modulation 해서, 이걸 결과의 index 로 활용..

return_result = result[hash(name) % 3000]

동일한 이름에 대해서는 항상 동일한 값이 나올 테고.. 결과에 대한 distribution 은 hash 함수를 어떤 걸로 하느냐에 따라 다르겠지만..
적당히 검색해서 아무거나 골라 써도 별 문제는 없는 상황 같네요.

md5 나 sha 같은 거 돌려서 나온 값에, mask 씌워서 원하는 범위가 되도록 잘라낸다거나.. 뭐.. 아래 링크처럼 적당히 만들어도 되겠네요.
http://www.linuxquestions.org/questions/programming-9/hash-function-in-c-595021/

되면 한다! / feel no sorrow, feel no pain, feel no hurt, there's nothing gained.. only love will then remain.. 『 Mizz 』

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.